How to set Default value on search form? - php

I'm using a wordpress real estate plugin for my project which is wpcasa, I already do some modification, But this thing takes my time to figure out.
I think they use array to get set values/labels on search form.
Anyone can Help me to how to add default value into a search form?
Here's the code below
$defaults = array(
'keyword' => array(
'label' => __( 'Keyword or Listing ID', 'wpcasa' ) . '…',
'type' => 'text',
'class' => 'width-3-4',
'priority' => 10
),
'submit' => array(
'label' => __( 'Search', 'wpcasa' ),
'type' => 'submit',
'class' => 'width-1-4',
'priority' => 20
),
'offer' => array(
'label' => __( 'Offer', 'wpcasa' ),
'key' => '_price_offer',
'data' => wpsight_offers(),
'type' => 'select',
'data_compare' => '=',
'class' => 'width-1-5',
'priority' => 30
),
'location' => array(
'data' => array(
// wp_dropdown_categories() options
'taxonomy' => 'location',
'show_option_none' => __( 'Location', 'wpcasa' ),
'option_none_value' => '',
'hierarchical' => 1,
'orderby' => 'ID',
'order' => 'ASC'
),
'type' => 'taxonomy_select',
'class' => 'width-1-5',
'priority' => 40
),
'listing-type' => array(
'data' => array(
// wp_dropdown_categories() options
'taxonomy' => 'listing-type',
'show_option_none' => __( 'Type', 'wpcasa' ),
'option_none_value' => '',
'hierarchical' => 1,
'orderby' => 'ID',
'order' => 'ASC'
),
'type' => 'taxonomy_select',
'class' => 'width-1-5',
'priority' => 50
),
$details['details_1']['id'] => array(
'label' => $details['details_1']['label'],
'key' => '_details_1',
'data' => $details['details_1']['data'],
'type' => 'select',
'data_compare' => '>=',
'class' => 'width-1-5',
'priority' => 60
),
$details['details_2']['id'] => array(
'label' => $details['details_2']['label'],
'key' => '_details_2',
'data' => $details['details_2']['data'],
'type' => 'select',
'data_compare' => '>=',
'class' => 'width-1-5',
'priority' => 70
)
);
`
Example on keyword I will set a value HOME Instead showing its label.
Thank you!

I got it now I should add 'default' => 'Myvalue',
example
'keyword' => array(
'label' => __( 'Keyword or Listing ID', 'wpcasa' ) . '…',
'type' => 'text',
'class' => 'width-3-4',
'default' => 'HELLO',
'priority' => 10
),
Thanks for the help/advice!

Related

How to add custom theme features of post into custom post type? Wordpress, php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
i created a custom post type but i only get default support features like thumbnails, exerpt etc but what i want is to add all extra features of ceris theme in posts into my custom post type can you help me out?
$args = array(
'label' => __( 'directory', 'Ceris' ),
'description' => __( 'directory all posts', 'Ceris' ),
'labels' => $labels,
// Features this CPT supports in Post Editor
'supports' => array( 'title', 'editor', 'excerpt','thumbnail', 'comments', 'revisions', 'custom-fields','post-formats','page-attributes','bk_review_score' ),
// You can associate this CPT with a taxonomy or custom taxonomy.
'taxonomies' => array( 'posts' ),
/* A hierarchical CPT is like Pages and can have
* Parent and child items. A non-hierarchical CPT
* is like Posts.
*/
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'show_in_rest' => true,
);
check my support array like i'm trying to add bk_review_system into my cpt
yes you can do it
try the following code, BK come with a filter to add widget and there configuration
function bk_child_register_meta_boxes($meta_boxes) {
$meta_boxes[] = array(
'id' => 'bk_review',
'title' => esc_html__( 'BK Review System', 'ceris' ),
'pages' => array( 'directory' ),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'type' => 'heading',
'name' => esc_html__('Author Review', 'ceris'),
'desc' => esc_html__('This section allow you to give your review, pros, cons', 'ceris'),
),
// Enable Review
array(
'name' => esc_html__( 'Review Box', 'ceris' ),
'id' => 'bk_review_checkbox',
'type' => 'checkbox',
'desc' => esc_html__( 'Enable Review On This Post', 'ceris' ),
'std' => 0,
),
array(
'visible' => array( 'bk_review_checkbox', '=', 1),
'type' => 'divider',
),
array(
'id' => 'bk_review_box_position',
'name' => esc_html__( 'Review Box Position', 'ceris' ),
'type' => 'select',
'options' => array(
'default' => esc_html__( 'Default -- Under the post content', 'ceris' ),
'top' => esc_html__( 'On top of the post content ', 'ceris' ),
),
// Select multiple values, optional. Default is false.
'multiple' => false,
'std' => 'default',
'visible' => array( 'bk_review_checkbox', '=', 1),
),
array(
'visible' => array( 'bk_review_checkbox', '=', 1),
'type' => 'divider',
),
array(
'name' => 'Product Image',
'id' => 'bk_review_product_img',
'type' => 'single_image',
'visible' => array( 'bk_review_checkbox', '=', 1),
),
array(
'name' => esc_html__( 'Product name', 'ceris' ),
'id' => 'bk_review_box_title',
'type' => 'textarea',
'cols' => 20,
'rows' => 2,
'visible' => array( 'bk_review_checkbox', '=', 1),
),
array(
'name' => esc_html__( 'Description', 'ceris' ),
'id' => 'bk_review_box_sub_title',
'type' => 'textarea',
'cols' => 20,
'rows' => 2,
'visible' => array( 'bk_review_checkbox', '=', 1),
),
array(
'visible' => array( 'bk_review_checkbox', '=', 1),
'type' => 'divider',
),
//Review Score
array(
'name' => esc_html__( 'Review Score', 'ceris' ),
'id' => 'bk_review_score',
'class' => 'ceris-',
'type' => 'slider',
'visible' => array( 'bk_review_checkbox', '=', 1),
'js_options' => array(
'min' => 0,
'max' => 10.05,
'step' => .1,
),
),
array(
'visible' => array( 'bk_review_checkbox', '=', 1),
'type' => 'divider',
),
// Summary
array(
'name' => esc_html__( 'Summary', 'ceris' ),
'id' => 'bk_review_summary',
'type' => 'textarea',
'cols' => 20,
'rows' => 4,
'visible' => array( 'bk_review_checkbox', '=', 1),
),
array(
'visible' => array( 'bk_review_checkbox', '=', 1),
'type' => 'divider',
),
//Pros & Cons
array(
'name' => esc_html__( 'Pros and Cons', 'ceris' ),
'id' => 'bk_pros_cons',
'type' => 'checkbox',
'desc' => esc_html__( 'Enable Pros and Cons On This Post', 'ceris' ),
'std' => 0,
'visible' => array( 'bk_review_checkbox', '=', 1),
),
array(
'visible' => array( 'bk_pros_cons', '=', 1),
'type' => 'divider',
),
array(
'name' => esc_html__( 'Pros Title', 'ceris' ),
'id' => 'bk_review_pros_title',
'type' => 'textarea',
'cols' => 20,
'rows' => 2,
'visible' => array( 'bk_pros_cons', '=', 1),
),
array(
'name' => esc_html__( 'Pros (Advantages)', 'ceris' ),
'id' => 'bk_review_pros',
'type' => 'textarea',
'cols' => 20,
'clone' => true,
'rows' => 2,
'visible' => array( 'bk_pros_cons', '=', 1),
),
array(
'visible' => array( 'bk_pros_cons', '=', 1),
'type' => 'divider',
),
array(
'name' => esc_html__( 'Cons Title', 'ceris' ),
'id' => 'bk_review_cons_title',
'type' => 'textarea',
'cols' => 20,
'rows' => 2,
'visible' => array( 'bk_pros_cons', '=', 1),
),
array(
'name' => esc_html__( 'Cons (Disadvantages)', 'ceris' ),
'id' => 'bk_review_cons',
'type' => 'textarea',
'cols' => 20,
'clone' => true,
'rows' => 2,
'visible' => array( 'bk_pros_cons', '=', 1),
),
array(
'type' => 'divider',
),
array(
'type' => 'heading',
'name' => esc_html__('Performance and User Review', 'ceris'),
'desc' => esc_html__('This section allow you to have some criterias and allow your reader to share their review', 'ceris'),
),
array(
'name' => esc_html__( 'Performance and User Review Check Box', 'ceris' ),
'id' => 'bk_performance_review_checkbox',
'type' => 'checkbox',
'desc' => esc_html__( 'Enable This Review', 'ceris' ),
'std' => 0,
),
array(
'visible' => array( 'bk_performance_review_checkbox', '=', 1),
'type' => 'divider',
),
array(
'id' => 'bk_performance_review_score_criteria_group',
// Group field
'type' => 'group',
// Clone whole group?
'clone' => true,
'visible' => array( 'bk_performance_review_checkbox', '=', 1),
// Sub-fields
'fields' => array(
array(
'name' => esc_html__( 'Criteria Title', 'ceris' ),
'id' => 'review_criteria_title',
'type' => 'text',
),
array(
'name' => esc_html__( 'Criteria Score', 'ceris' ),
'id' => 'review_criteria_score',
'class' => 'ceris-',
'type' => 'slider',
'js_options' => array(
'min' => 0,
'max' => 10.05,
'step' => .1,
),
),
),
),
array(
'type' => 'divider',
),
array(
'name' => esc_html__( 'Reader Review Form', 'ceris' ),
'id' => 'bk_reader_review_checkbox',
'visible' => array( 'bk_performance_review_checkbox', '=', 1),
'type' => 'checkbox',
'desc' => esc_html__( 'Enable Reader Review', 'ceris' ),
'std' => 0,
),
)
);
return $meta_boxes;
}
add_filter( 'rwmb_meta_boxes', 'bk_child_register_meta_boxes', 999,1 );

WP ACF Generate php – Where and how to put the code?

On my WordPress website I have the ACF plugin installed and I'm using the fields on several pages in the 'regular' way. So I created the groups and fields in the backend. Everything works fine.
Now I want to generate php code of a couple of those field groups (because I want to change the code slightly). Where do I put the code and what’s the best way to do this?
I've created a new php file acf-deals.php and uploaded it to the /php-includes/ directory in the root directory. It includes the following code:
<?php
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_deal1',
'title' => 'Deal One (displayed on homepage)',
'fields' => array(
array(
'key' => 'field_5c66e017f8359',
'label' => 'Title',
'name' => 'deal_title_one',
'type' => 'text',
'instructions' => '(max. 100 characters)',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => 'deals-title',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => 100,
),
array(
'key' => 'field_5c6d43781bcb1',
'label' => 'Deal or Discount',
'name' => 'discount_deal_or_special_one',
'type' => 'radio',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5c66e017f8359',
'operator' => '!=empty',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array(
'Discount' => 'Discount',
'Deal' => 'Deal',
),
'allow_null' => 1,
'other_choice' => 0,
'default_value' => '',
'layout' => 'vertical',
'return_format' => 'value',
'save_other_choice' => 0,
),
array(
'key' => 'field_5c66e094f835a',
'label' => 'Description',
'name' => 'deal_description_one',
'type' => 'textarea',
'instructions' => '(max. 600 characters)',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5c66e017f8359',
'operator' => '==empty',
),
),
),
'wrapper' => array(
'width' => '',
'class' => 'deals-description',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'maxlength' => 600,
'rows' => '',
'new_lines' => '',
),
array(
'key' => 'field_5c66e0d4f835b',
'label' => 'Regular price',
'name' => 'regular_price_one',
'type' => 'number',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => 'deals-regular-price',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '$',
'append' => '',
'min' => '',
'max' => '',
'step' => '',
),
array(
'key' => 'field_5c66e130f835c',
'label' => 'Discounted price / deal price',
'name' => 'discounted_price_one',
'type' => 'number',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => 'deals-discounted-price',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '$',
'append' => '',
'min' => '',
'max' => '',
'step' => '',
),
array(
'key' => 'field_5c703c1fd5851',
'label' => 'Valid until',
'name' => 'valid_until_one',
'type' => 'date_picker',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'display_format' => 'm/d/Y',
'return_format' => 'm/d/Y',
'first_day' => 1,
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
array(
'param' => 'post_format',
'operator' => '==',
'value' => 'aside',
),
),
array(
array(
'param' => 'post_format',
'operator' => '==',
'value' => 'status',
),
),
),
'menu_order' => 1,
'position' => 'acf_after_title',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => 1,
'description' => '',
));
endif;
?>
I've added this code to my single-aside.php file:
<?php get_template_part( '/php-includes/acf-deals.php', 'acf-deals' ); ?>
Unfortunately the field are not showing up in the WP admin backend. What am I doing wrong? I searched and searched but can't find a proper explanation or a way to fix it. I hope someone can help.
Thanks for your help!
add_action('acf/init', function(){
... add local fields
})

Zend 2 Form Select multiple : How to preselect values

I have the following form element configured and i don't know why the values are not preselected.
$this->add(array(
'name' => 'item_ids',
'type' => 'Select',
'attributes' => array(
'id' => 'item_ids',
'class' => 'form-control',
'multiple' => 'multiple',
'value' => array('1','2'),
),
'options' => array(
'label' => 'Items',
'label_attributes' => array(
'class' => 'col-sm-2 control-label',
),
'value_options' => array(
'1' =>'Item 1',
'2' =>'Item 2',
'3' =>'Item 3'
),
)
));
I want that the "Item 1" and "Item 2" are preselected.
I hope someone can help me with my problem.
#### Update ####
Found something like that in the documentation, i will give it a try :
'value_options' => array(
array(
'value' => '1',
'label' => 'Orange',
'selected' => true,
),
array(
'value' => '2',
'label' => 'Lemon',
),
),
you can set form values like :
$form->getElement('selector')->setValue('val');
or
$form->setDefaults(array(
'selector' => 'val'
));
As I mentioned in the Update of my first post, I found something that seemed to be the right way.
I tested it and this is the solution :
$this->add(array(
'name' => 'item_ids',
'type' => 'Select',
'attributes' => array(
'id' => 'item_ids',
'class' => 'form-control',
'multiple' => 'multiple',
),
'options' => array(
'label' => 'Items',
'label_attributes' => array(
'class' => 'col-sm-2 control-label',
),
'value_options' => array(
array(
'value' => '1',
'label' => 'Item 1',
'selected' => true,
),
array(
'value' => '2',
'label' => 'Item 2',
'selected' => true,
),
array(
'value' => '3',
'label' => 'Item 3',
),
),
)
));

CGridview fit with screen Resolution without Scroll

Im using Editable Grid extension of CGridview.
MY Grid:
$this->widget('EditableGrid', array(
'dataProvider' => $dataProvider,
'template' => '{items}{pager} ',
'id' => 'PO-grid',
'htmlOptions'=>array(
//'style'=>'width:1100px;'
),
'columns' => array(
array(
'class' => 'EditableGridColumn',
'header' => '',
'name' => 'PO_{gridNum}_{rowNum}_edit',
'imageurl'=> Yii::app()->request->baseUrl.'/images/update.png',
'tag' => 'button',
'tagHtmlOptions' => array(
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'StentysRef',
'name' => '[{gridNum}][{rowNum}]ref',
'tag' => 'textField',
'tagHtmlOptions' => array(
'readonly'=>true
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'SupplierRef',
'name' => '[{gridNum}][{rowNum}]productref',
'tag' => 'textField',
'tagHtmlOptions' => array(
'readonly'=>true
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'Product',
'name' => '[{gridNum}][{rowNum}]productname',
'tag' => 'textField',
'tagHtmlOptions' => array(
// 'size' => '2'
'readonly'=>true
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'Qty',
'name' => '[{gridNum}][{rowNum}]qty',
'tag' => 'textField',
'tagHtmlOptions' => array(
'size' => '2',
'readonly'=>true,'width'=>'10px','style'=>'width:70px;'
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'Description',
'name' => '[{gridNum}][{rowNum}]description',
'tag' => 'textField',
'tagHtmlOptions' => array(
// 'size' => '5'
'readonly'=>true
)
),
array('class'=>'CButtonColumn','template' => '{delete}',
'buttons'=>array(
'delete' => array(
'options'=>array('style'=>'margin-left:20px'),
'imageUrl'=>\Yii::app()->request->baseUrl.'/images/delete.png', )
),
),
),
));?>
My problem is, Gridview is fit with 1600 X 900 px screen , it should not fit with below px.
Anyone please help me to reolve this problem.
I want to make this grid fit with screen 1366 px.

loop options into array

I have an array that has a value with multiple options that is broken down into it's own array. One of those values I want to populate with a loop. Is this possible with the ; in the forloop I would think it would break. What is the best way to accomplish this request?
array(
'name' => __('Ensemble List', 'januas'),
'type' => 'checkbox',
'options' => array(
for ($x=0; $x<=10; $x++){
array('name' => __($x , 'title'), 'value' => $x)
}
)
),
Here is the complete array outside of what I posted:
$meta_boxes[] = array(
'id' => 'januas_speakers',
'title' => __('Ensemble', 'januas'),
'pages' => array('ja-event'),
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
'fields' => array(
array(
'name' => __('Visible', 'januas'),
'desc' => __('Select Yes to show the box in the event page, No to hide it.', 'januas'),
'id' => 'januas_speakers_visible',
'type' => 'select',
'options' => array(
array('name' => __('Yes', 'januas'), 'value' => 'y'),
array('name' => __('No', 'januas'), 'value' => 'n'),
)
),
array(
'name' => __('Position', 'januas'),
'desc' => __('Select the preferred position for the box.', 'januas'),
'id' => 'januas_speakers_position',
'type' => 'select',
'options' => array(
array('name' => __('Main', 'januas'), 'value' => 'main'),
array('name' => __('Sidebar', 'januas'), 'value' => 'sidebar'),
)
),
array(
'name' => __('Order', 'januas'),
'desc' => __('Insert the box order (ex: 1).', 'januas'),
'id' => 'januas_speakers_order',
'std' => 1,
'type' => 'text_small'
),
array(
'name' => __('Show Title', 'januas'),
'desc' => __('Select Yes to show the box title, No to hide it.', 'januas'),
'id' => 'januas_speakers_showtitle',
'type' => 'select',
'options' => array(
array('name' => __('Yes', 'januas'), 'value' => 'y'),
array('name' => __('No', 'januas'), 'value' => 'n'),
)
),
array(
'name' => __('Show in Top menu', 'januas'),
'desc' => __('Select Yes to show the menu item in the event page top menu, No to hide it.', 'januas'),
'id' => 'januas_speakers_showinmenu',
'type' => 'select',
'options' => array(
array('name' => __('Yes', 'januas'), 'value' => 'y'),
array('name' => __('No', 'januas'), 'value' => 'n'),
)
),
array(
'name' => '',
'desc' => '',
'id' => 'januas_images_gallery',
'type' => 'image_gallery'
),
array(
'name' => __('Ensemble List', 'januas'),
'desc' => 'Select the ensemble memebers for this event.',
'id' => 'januas_speakers_completelist',
'type' => 'checkbox',
'options' => array_map(function ($x) {
return array(
'name' => __($x, 'januas'),
'value' => $x,
);
}, range(0,11))
),
array(
'name' => __('Display order', 'januas'),
'desc' => '',
'id' => 'januas_speakers_speakersorder',
'type' => 'event_speakers'
),
array(
'name' => '',
'desc' => '',
'id' => 'januas_speakers_backtotop',
'type' => 'backtotop'
)
),
);
You could use array_map:
array(
'name' => __('Ensemble List', 'januas'),
'type' => 'checkbox',
'options' => array_map(function ($x) {
return array(
'name' => __($x, 'title'),
'value' => $x,
);
}, range(0,11))
),
You should use array_push
$a = array(
'name' => __('Ensemble List', 'januas'),
'type' => 'checkbox',
'options' => array()
);
for ($x=0; $x<=10; $x++){
array_push( $a['options'], array('name' => __($x , 'title'), 'value' => $x) );
}
print_r($a);
Do you need to run the loop inside of options? How about this approach.
$foo = array();
for ($x=0;$x<10;$x++)
$foo[] = $x;
$bar = array(
'name' => 'hello',
'options' => $foo
);
print_r($bar);
https://eval.in/54925

Categories