Search posts with meta data in Wordpress - php

I have created a site for study in abroad and i want to create search form for courses in site. I have added meta box for posting, but i cannot solve search form for meta data in posts.
Search form must be:
1) Countries
2) Course Languaes
3) Course Types
4) City of School
This is code in functions.php
if ( ! function_exists( 'thim_add_course_meta' ) ) {
function thim_add_course_meta( $meta_box ) {
$fields = $meta_box['fields'];
$fields[] = array(
'name' => esc_html__( 'Yaş Həddi', 'eduma' ),
'id' => 'thim_course_age',
'type' => 'text',
'desc' => esc_html__( 'yas heddi', 'eduma' ),
'std' => esc_html__( '18', 'eduma' )
);
$fields[] = array(
'name' => esc_html__( 'Dil', 'eduma' ),
'id' => 'thim_course_language',
'type' => 'text',
'desc' => esc_html__( 'Language\'s used for studying', 'eduma' ),
'std' => esc_html__( 'English', 'eduma' )
);
$fields[] = array(
'name' => esc_html__( 'Şəhər', 'eduma' ),
'id' => 'thim_course_city',
'type' => 'text',
'desc' => esc_html__( 'Language\'s used for studying', 'eduma' ),
'std' => esc_html__( 'Şəhər', 'eduma' )
);
$fields[] = array(
'name' => esc_html__( 'Ölkə', 'eduma' ),
'id' => 'thim_course_country',
'type' => 'text',
'desc' => esc_html__( 'Language\'s used for studying', 'eduma' ),
'std' => esc_html__( 'Ölkə', 'eduma' )
);
$meta_box['fields'] = $fields;
return $meta_box;
}
}
And how to i can change meta box type (from text to array)?

Related

Updating WooCommerce Admin Shipping Order Fields

In functions.php I am trying to use this, but it is not working:
function rt_woocommerce_admin_shipping_fields( $fields ) {
$fields['first_name']['value'] = $_GET['f'];
$fields['last_name']['value'] = $_GET['l'];
$fields['address_1']['value'] = $_GET['a'];
$fields['address_2']['value'] = $_GET['b'];
// etc
// etc
return $fields;
}
add_filter( 'woocommerce_admin_shipping_fields', 'rt_woocommerce_admin_shipping_fields' );
woocommerce_admin_billing_fields() works but the shipping function does not. Any advice? I need to update the fields with $_GET variables on page load. This works perfectly for the billing fields.
The array has label and show indexes for each item in shipping fields. There is no value index by default. See the woocommerce_admin_shipping_fields filter below.
self::$shipping_fields = apply_filters(
'woocommerce_admin_shipping_fields',
array(
'first_name' => array(
'label' => __( 'First name', 'woocommerce' ),
'show' => false,
),
'last_name' => array(
'label' => __( 'Last name', 'woocommerce' ),
'show' => false,
),
'company' => array(
'label' => __( 'Company', 'woocommerce' ),
'show' => false,
),
'address_1' => array(
'label' => __( 'Address line 1', 'woocommerce' ),
'show' => false,
),
'address_2' => array(
'label' => __( 'Address line 2', 'woocommerce' ),
'show' => false,
),
'city' => array(
'label' => __( 'City', 'woocommerce' ),
'show' => false,
),
'postcode' => array(
'label' => __( 'Postcode / ZIP', 'woocommerce' ),
'show' => false,
),
'country' => array(
'label' => __( 'Country / Region', 'woocommerce' ),
'show' => false,
'type' => 'select',
'class' => 'js_field-country select short',
'options' => array( '' => __( 'Select a country / region…', 'woocommerce' ) ) + WC()->countries->get_shipping_countries(),
),
'state' => array(
'label' => __( 'State / County', 'woocommerce' ),
'class' => 'js_field-state select short',
'show' => false,
),
'phone' => array(
'label' => __( 'Phone', 'woocommerce' ),
),
)
);

CMB2 repeatable file_list type

I am searching everywhere for an example of how to populate/access images entered inside of repeatable file-list group in CMB2. All the examples I could find is only for a single image: here is the link https://github.com/CMB2/CMB2/wiki/Field-Types#group
MY CODE:
// creating a group
$group_field_id = $bautage->add_field( array(
id' => 'tagen_entries',
'type' => 'group',
'description' => __( 'Tagen', 'cmb2' ),
'repeatable' => true,
'options' => array(
'group_title' => __( 'Tagen {#}', 'cmb2' ), // since version 1.1.4, {#} gets replaced by row number
'add_button' => __( 'Add Another Entry', 'cmb2' ),
'remove_button' => __( 'Remove Entry', 'cmb2' ),
'sortable' => true,
),
) );
// creating repeatable fields
$bautage->add_group_field( $group_field_id, array(
'name' => 'Tag Name',
'id' => 'tag_name',
'type' => 'text',
) );
$bautage->add_group_field( $group_field_id, array(
'name' => 'Tage Photos',
'id' => 'tage_photos',
'type' => 'file_list',
) );
// page code
$tagen_entries = get_post_meta( get_the_ID(), 'tagen_entries', true );
foreach ( (array) $tagen_entries as $key => $entry ) {
if ( isset( $entry['tag_name'] ) ) {
$tag_name = esc_html( $entry['tag_name'] );
echo $tag_name;
}
if ( isset( $entry['tage_bildern'] ) ) {
// loop to bring all the photos
// also need the first photo from each entry to be used as a click trigger to open the slideshow
}
}

wordpress redux framework - create a repeater field and show values later

I am trying to use Redux inside the wordpress theme and not as a plugin. In functions.php I included both redux-framework.php and sample-config.php .
Now I need to create a repeater field.
From Redux doc, I got the following code to use in order to create a repeater field:
$this->sections[] = array(
'title' => __('Repeater Field', 'redux-framework-demo' ),
'icon' => 'el-icon-thumbs-up',
'fields' => array(
array(
'id' => 'repeater-field-id',
'type' => 'repeater',
'title' => __( 'Title', 'redux-framework-demo' ),
'subtitle' => __( '', 'redux-framework-demo' ),
'desc' => __( '', 'redux-framework-demo' ),
//'group_values' => true, // Group all fields below within the repeater ID
//'item_name' => '', // Add a repeater block name to the Add and Delete buttons
//'bind_title' => '', // Bind the repeater block title to this field ID
//'static' => 2, // Set the number of repeater blocks to be output
//'limit' => 2, // Limit the number of repeater blocks a user can create
//'sortable' => false, // Allow the users to sort the repeater blocks or not
'fields' => array(
array(
'id' => 'title_field',
'type' => 'text',
'placeholder' => __( 'Title', 'redux-framework-demo' ),
),
array(
'id' => 'text_field',
'type' => 'text',
'placeholder' => __( 'Text Field', 'redux-framework-demo' ),
),
array(
'id' => 'select_field',
'type' => 'select',
'title' => __( 'Select Field', 'redux-framework-demo' ),
'options' => array(
'1' => __( 'Option 1', 'redux-framework-demo' ),
'2' => __( 'Option 2', 'redux-framework-demo' ),
'3' => __( 'Option 3', 'redux-framework-demo' ),
),
'placeholder' => __( 'Listing Field', 'redux-framework-demo' ),
),
)
)
)
);
but if I place the code inside functions.php, what will the $this variable refer to? It'll produce errors. So how to use the snippet so that I can retrieve the values from template files as well?
You have to tried an old version system to create a section. You can try the new version system, I'm not sure if this works or not, but you can try this way:
Redux::setSection($opt_name, array(
'title' => __('Ads Sections', 'cbnews'),
'id' => 'ads-sections',
'desc' => __('You can manage your ads', 'cbnews'),
'icon' => 'dashicons dashicons-dashboard',
'fields' => array(
array(
'id' => 'repeater-field-id',
'type' => 'repeater',
'title' => __( 'Title', 'redux-framework-demo' ),
'subtitle' => __( '', 'redux-framework-demo' ),
'desc' => __( '', 'redux-framework-demo' ),
//'group_values' => true, // Group all fields below within the repeater ID
//'item_name' => '', // Add a repeater block name to the Add and Delete buttons
//'bind_title' => '', // Bind the repeater block title to this field ID
//'static' => 2, // Set the number of repeater blocks to be output
//'limit' => 2, // Limit the number of repeater blocks a user can create
//'sortable' => false, // Allow the users to sort the repeater blocks or not
'fields' => array(
array(
'id' => 'title_field',
'type' => 'text',
'placeholder' => __( 'Title', 'redux-framework-demo' ),
),
array(
'id' => 'text_field',
'type' => 'text',
'placeholder' => __( 'Text Field', 'redux-framework-demo' ),
),
array(
'id' => 'select_field',
'type' => 'select',
'title' => __( 'Select Field', 'redux-framework-demo' ),
'options' => array(
'1' => __( 'Option 1', 'redux-framework-demo' ),
'2' => __( 'Option 2', 'redux-framework-demo' ),
'3' => __( 'Option 3', 'redux-framework-demo' ),
),
'placeholder' => __( 'Listing Field', 'redux-framework-demo' ),
),
)
)
)
));

Adding meta box is only appearing in add new post not appearing in page

add_filter( 'rwmb_meta_boxes', 'your_prefix_meta_boxes' );
function your_prefix_meta_boxes( $meta_boxes ) {
$meta_boxes[] = array(
'title' => __( 'Test Meta Box', 'textdomain' ),
'post_types' => 'post',
'fields' => array(
array(
'id' => 'name',
'name' => __( 'Name', 'textdomain' ),
'type' => 'text',
),
array(
'id' => 'gender',
'name' => __( 'Gender', 'textdomain' ),
'type' => 'radio',
'options' => array(
'm' => __( 'Male', 'textdomain' ),
'f' => __( 'Female', 'textdomain' ),
),
),
array(
'id' => 'email',
'name' => __( 'Email', 'textdomain' ),
'type' => 'email',
),
),
);
return $meta_boxes;
}
i had pud this code in my function.php and i am getting meta box in add new post only. i need meta box also on my page. please help me out
You should select one of the hooks available on your pages and to add your function there. For example use page_template hook:
add_filter( 'page_template', 'your_prefix_meta_boxes' );

Wordpress metabox not showing up

I need a Webinar in my wordpress site. So I'm registering an meta box for my custom post type. I can see my custom post in the wordpress admin panel, but inside the custom post meta box is missing. What is wrong here!
// Meta boxes
add_filter( 'rwmb_meta_boxes', 'navbig_webinars_register_meta_boxes' );
//Register meta boxes
function navbig_webinars_register_meta_boxes( $meta_boxes )
{
$prefix = 'navbig_webinars_';
$meta_boxes[] = array(
'id' => 'standard',
'title' => __( 'Webinar Data', 'rwmb' ),
'pages' => array( 'webinar' ),
'context' => 'normal',
'priority' => 'high',
'autosave' => true,
'fields' => array(
array(
'name' => __( 'Date of Webinar', 'rwmb' ),
'id' => "webinar_date",
'type' => 'date',
// jQuery date picker options. See here http://api.jqueryui.com/datepicker
'js_options' => array(
'dateFormat' => __( 'dd-MM-yy', 'rwmb' ),
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
),
),
array(
'name' => __( 'Location', 'rwmb' ),
'id' => "webinar-location",
'type' => 'text',
'std' => __( 'Default text value', 'rwmb' ),
),
array(
'name' => __( 'Time Of Webinar', 'rwmb' ),
'id' => 'webinar_time',
'type' => 'time',
'js_options' => array(
'stepMinute' => 5,
'showSecond' => true,
'stepSecond' => 10,
),
),
array(
'name' => __( 'Select Time Zone', 'rwmb' ),
'id' => "select-timezone",
'type' => 'select_advanced',
'options' => array(
'value1' => __( 'PST', 'rwmb' ),
'value2' => __( 'EST', 'rwmb' ),
),
'multiple' => false,
'placeholder' => __( 'Select an Coures Type', 'rwmb' ),
),
// URL
array(
'name' => __( 'Webinar URL', 'rwmb' ),
'id' => "webinar_url",
'type' => 'url',
'std' => 'http://google.com',
),
array(
'name' => __( 'Webinar Banner', 'rwmb' ),
'id' => "webinar_banner",
'type' => 'thickbox_image',
),
),
);
return $meta_boxes;
}
You can find more detail about meta boxes here.
Here is sample add_meta_box code:-
add_meta_box(
'some_meta_box_name'
,__( 'Some Meta Box Headline', 'plugin_textdomain' )
,'render_meta_box_content' //this is callback function.
,'post_type'
,'advanced'
,'high'
);

Categories