How can i use Option Tree custom post type checkbox in wordpress - wordpress

array(
'id' => 'custom_post_type_checkbox',
'label' => __( 'Custom Post Type Select', 'theme-text-domain' ),
'desc' => sprintf( __( 'Check box' ),
'std' => '',
'type' => 'custom-post-type-checkbox',
'section' => '',
'rows' => '',
'post_type' => 'newyork-offices',
'taxonomy' => '',
'min_max_step'=> '',
'class' => '',
'condition' => '',
'operator' => 'and'
),
This is custom post type check box and i got all posts in my page template. so How can i use it my page template ?
What is the loop function for this ?

Related

Wordpress - Trying to display date from custom form two different ways

I am trying to create an events page in Wordpress. I am using the Advanced Custom Fields plugin to generate my forms. I would like to style the month and year differently from the day in the listing section. However, I don't want to make the user have to input the same date twice in the back-end just for this. Is there a way to display the content from the one form in two different calibrations on the front-end? For example, can I display it once as month and year then once again as just the day? Is there any other workaround? Any advice would be appreciated.
Here is my custom form code:
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_5fec83c0a2f7b',
'title' => 'Event Particulars',
'fields' => array(
array(
'key' => 'field_5fec83ca0dc8b',
'label' => 'Date of event',
'name' => 'date_of_event',
'type' => 'date_picker',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5fec84a00dc8c',
'operator' => '!=empty',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'display_format' => 'Y F j',
'return_format' => 'Y F j',
'first_day' => 1,
),
array(
'key' => 'field_5fec84a00dc8c',
'label' => '',
'name' => '',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
'location' => array(
array(
array(
'param' => 'page_type',
'operator' => '==',
'value' => 'front_page',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
endif;
You can load the value of the date field, create a date object and then format that date object as you prefer:
// Load field value.
$date_string = get_field('date_of_event');
// Create DateTime object from value.
// Here you must use the format that you specified as the "return format" of the date field in ACF.
$date = DateTime::createFromFormat('Y F j', $date_string);
// Now you can use the date object to print the date in different formats:
echo $date->format('M Y');
echo $date->format('j M Y');
Have a look at the "Modifiy value" section of the docs:
https://www.advancedcustomfields.com/resources/date-picker/

SSL breaks a users ability to upload an image

I have a problem that is driving me crazy. I'm working on a business listing website in WordPress which allows business users to upload their businesses, along with a description and an image.
All was working fine in development but as soon as a SSL is installed on the site, image uploads produce an error:
An error occurred in the upload. Please try again later.
The inspector console shows:
400 error: Failed to load resource: the server responded with a status of 400 (Bad Request)
and the file cannot be uploaded.
I'm out of my depth here - any ideas please?
I think this is the relevant part of the theme library - not sure it it helps?
<?php
if ( ! search_and_go_elated_listing_plugin_installed() ) {
//exit if listing plugin is not installed
return;
}
if(!function_exists('search_and_go_elated_map_listing_type_settings')) {
function search_and_go_elated_map_listing_type_settings() {
$meta_box_listing_type = search_and_go_elated_create_meta_box(array(
'scope' => 'listing-type-item',
'title' => 'Listing Type Settings',
'name' => 'listing_type_settings_meta_box'
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_phone',
'type' => 'yesno',
'label' => esc_html__( 'Show Phone Field', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_website',
'type' => 'yesno',
'label' => esc_html__( 'Show Website Field', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_email',
'type' => 'yesno',
'label' => esc_html__( 'Show Email Field', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_gallery',
'type' => 'yesno',
'label' => esc_html__( 'Show Gallery Images', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_video',
'type' => 'yesno',
'label' => esc_html__( 'Show Video', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_audio',
'type' => 'yesno',
'label' => esc_html__( 'Show Audio', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_work_hours',
'type' => 'yesno',
'label' => esc_html__( 'Show Working Hours', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_social_icons',
'type' => 'yesno',
'label' => esc_html__( 'Show Social Icons', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_price',
'type' => 'yesno',
'label' => esc_html__( 'Show Price', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_sidebar_gallery',
'type' => 'yesno',
'label' => esc_html__( 'Show Sidebar Gallery', 'search-and-go' ),
'description' => '',
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_booking_form',
'type' => 'yesno',
'label' => esc_html__( 'Show Booking Form', 'search-and-go' ),
'description' => esc_html__( 'Requires Elated Booking Plugin to be installed', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
//init icon pack hide and show array. It will be populated dinamically from collections array
$listing_type_icon_pack_hide_array = array();
$listing_type_icon_pack_show_array = array();
//do we have some collection added in collections array?
if (is_array(search_and_go_elated_icon_collections()->iconCollections) && count(search_and_go_elated_icon_collections()->iconCollections)) {
//get collections params array. It will contain values of 'param' property for each collection
$listing_type_icon_collections_params = search_and_go_elated_icon_collections()->getIconCollectionsParams();
//foreach collection generate hide and show array
foreach (search_and_go_elated_icon_collections()->iconCollections as $dep_collection_key => $dep_collection_object) {
$listing_type_icon_pack_hide_array[$dep_collection_key] = '';
//we need to include only current collection in show string as it is the only one that needs to show
$listing_type_icon_pack_show_array[$dep_collection_key] = '#eltd_listing_type_icon_' . $dep_collection_object->param . '_container';
//for all collections param generate hide string
foreach ($listing_type_icon_collections_params as $listing_icon_collections_param) {
//we don't need to include current one, because it needs to be shown, not hidden
if ($listing_icon_collections_param !== $dep_collection_object->param) {
$listing_type_icon_pack_hide_array[$dep_collection_key] .= '#eltd_listing_type_icon_' . $listing_icon_collections_param . '_container,';
}
}
//remove remaining ',' character
$listing_type_icon_pack_hide_array[$dep_collection_key] = rtrim($listing_type_icon_pack_hide_array[$dep_collection_key], ',');
}
}
search_and_go_elated_create_meta_box_field(
array(
'parent' => $meta_box_listing_type,
'type' => 'select',
'name' => 'listing_type_icon_pack',
'default_value' => 'font_awesome',
'label' => esc_html__( 'Listing Type Icon Pack', 'search-and-go' ),
'description' => esc_html__( 'Choose icon pack for listing', 'search-and-go' ),
'options' => search_and_go_elated_icon_collections()->getIconCollections(),
'args' => array(
'dependence' => true,
'hide' => $listing_type_icon_pack_hide_array,
'show' => $listing_type_icon_pack_show_array
)
)
);
if (is_array(search_and_go_elated_icon_collections()->iconCollections) && count(search_and_go_elated_icon_collections()->iconCollections)) {
//foreach icon collection we need to generate separate container that will have dependency set
//it will have one field inside with icons dropdown
foreach (search_and_go_elated_icon_collections()->iconCollections as $collection_key => $collection_object) {
$icons_array = $collection_object->getIconsArray();
//get icon collection keys (keys from collections array, e.g 'font_awesome', 'font_elegant' etc.)
$icon_collections_keys = search_and_go_elated_icon_collections()->getIconCollectionsKeys();
//unset current one, because it doesn't have to be included in dependency that hides icon container
unset($icon_collections_keys[array_search($collection_key, $icon_collections_keys)]);
$listing_icon_hide_values = $icon_collections_keys;
$listing_icon_container = search_and_go_elated_add_admin_container(
array(
'parent' => $meta_box_listing_type,
'name' => 'listing_type_icon_' . $collection_object->param . '_container',
'hidden_property' => 'listing_type_icon_pack',
'hidden_value' => '',
'hidden_values' => $listing_icon_hide_values
)
);
search_and_go_elated_create_meta_box_field(
array(
'parent' => $listing_icon_container,
'type' => 'select',
'name' => 'listing_type_icon_' . $collection_object->param,
'default_value' => '',
'label' => esc_html__( 'Listing Type Icon', 'search-and-go' ),
'description' => esc_html__( 'Choose Listing Type Icon', 'search-and-go' ),
'options' => $icons_array,
)
);
}
}
search_and_go_elated_add_custom_fields_creator(array(
'name' => 'listing_custom_fields' ,
'label' => esc_html__( 'Custom Fields Creator', 'search-and-go' ),
'desciption' => esc_html__( 'Create listing type custom fields', 'search-and-go' ),
'parent' => $meta_box_listing_type
));
$feature_list_title = search_and_go_elated_add_admin_section_title(
array(
'parent' => $meta_box_listing_type,
'title' => esc_html__( 'Listing Type Feature List', 'search-and-go' ),
'name' => 'listing_type_feature_list_title'
)
);
search_and_go_elated_add_repeater_field(array(
'name' => 'eltd_listing_type_repeater',
'parent' => $meta_box_listing_type,
'fields' => array(
array(
'type' => 'textsimple',
'name' => 'eltd_listing_type_feature_list',
'label' => '',
'description' => '',
),
)
)
);
}
add_action('search_and_go_elated_meta_boxes_map', 'search_and_go_elated_map_listing_type_settings');
}

Calling custom post type in plugin itself

I am writing a plugin in which I have below custom post type:
function create_post_type_contact() {
register_post_type('contact',
array(
'labels' => array(
'name' => __( 'Contacts'),
'singular_name' => __( 'contact'),
'add_new' => __('Add New contact' ),
'add_new_item' => __('Add New contact' ),
'edit_item' => 'Edit Contact',
'new_item' => 'New Contact',
'view_item' => 'View Contact',
'search_items' => 'Search Contact',
'not_found' => 'No contacts found',
'not_found_in_trash' => 'No contacts found in Trash'
),
'public' => true,
'menu_position' => 24,
'menu_icon' => 'dashicons-email',
'rewrite' => array(
'slug' => __('contact')
),
'supports' => array( 'title'),
));
}
Also have added below custom meta fields:
// Field Array
$custom_meta_fields_contact = array(
array(
'label'=> __('Contact Name'),
'desc' => 'Enter Contact Name here',
'id' => 'contact_name',
'type' => 'text'
),
array(
'label'=> __('Contact Address'),
'desc' => 'Enter Contact address here',
'id' => 'contact_address',
'type' => 'textarea'
),
array(
'label'=> __('Contact No'),
'desc' => 'Enter Contact number here',
'id' => 'contact_no',
'type' => 'text'
),
array(
'label'=> __('Contact Email'),
'desc' => 'enter contact email id here',
'id' => 'contact_email',
'type' => 'text'
),
);
I have added functions to show custom meta fields and save custom meta, which is OK and working.
Within this plugin I need to call contact_email meta field. For which I have added following code :
// get the Contact email address
$args_contact = array('post_type' => 'contact');
$contact_posts = new WP_Query($args_contact);
if($contact_posts->have_posts()) :
while($contact_posts->have_posts()) : $contact_posts->the_post();
$to = get_post_meta($post->ID, 'contact_email');
endwhile; endif;
wp_reset_query();
But whenever I am trying to get the value of $to inside the plugin , its returning nothing. Where as in the contact page am able to get and display contact_name, contact_number, contact_address and contact_email properly.
Any help or suggestion will be appreciated.
Use this
get_post_meta(get_the_ID(), 'contact_email', true);
OR declare global $post variable after if condition
if($contact_posts->have_posts()) :
global $post;

make CMB text_datetime_timestamp field repeatable

I'm using CMB to creat custom fields for wordpress custom post
https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress
I'm using text_datetime_timestamp to set date and time and I need to make this field repeatable which is not
as I go through the documentation we can make new fields but I can't figure out how it make "text_datetime_timestamp" field repeatable
any body can show me the way to accomplish that ?
thank you
I did not find a solution to make the field repeatable so I put the field inside group and made it repeatable
array(
'id' => $prefix . 'repeat_date_group',
'type' => 'group',
'description' => '',
'options' => array(
'group_title' => __( 'Date/Time {#}', 'cmb' ),
'add_button' => __( 'Add Another Date/Time', 'cmb' ),
'remove_button' => __( 'Remove Date/Time', 'cmb' ),
'sortable' => true, // beta
),
'fields' => array(
array(
'name' => 'Date/Time',
'desc' => '',
'id' => $prefix . 'course_date',
'type' => 'text_datetime_timestamp'
),
),
),
I hope this answer will help somebody
Well here is my code, you may try this
$cmb= new_cmb2_box( array(
'id' => $prefix.'testing',
'title' => _('Testing'),
'object_types' => array('post'),
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
));
$cmb->add_field( array(
'name' => 'Test Date/Time Picker Combo (UNIX timestamp)',
'id' => 'wiki_test_datetime_timestamp',
'type' => 'text_datetime_timestamp',
'repeatable' => true,
) );

Get value from option tree wordpress

I want to be use some sliders in my wordpress theme. I want to select them in my theme option. I am using the code below.
<?php
$slider_select = get_option_tree( 'slider_select', '', 'true' );
?>
<?php get_template_part('$slider_select'); ?>
But, it is not working. I want the get_template_part code worked. Any suggestion?
replace
get_template_part('$slider_select');
with
get_template_part($slider_select);
You can use this method for create a slider in option tree.
create settings array like this.
array(
'id' => 'my_slider',
'label' => 'Images',
'desc' => '',
'std' => '',
'type' => 'list-item',
'section' => 'general',
'class' => '',
'choices' => array(),
'settings' => array(
array(
'id' => 'slider_image',
'label' => 'Image',
'desc' => '',
'std' => '',
'type' => 'upload',
'class' => '',
'choices' => array()
),
array(
'id' => 'slider_link',
'label' => 'Link to Post',
'desc' => 'Enter the posts url.',
'std' => '',
'type' => 'text',
'class' => '',
'choices' => array()
),
array(
'id' => 'slider_description',
'label' => 'Description',
'desc' => 'This text is used to add fancy captions in the slider.',
'std' => '',
'type' => 'textarea',
'class' => '',
'choices' => array()
)
)
)
Add into page using loop
$my_slider = ot_get_option( 'my_slider' );
foreach($my_slider as $slider){
echo '<img src="'.$slider["slider_image"].'">';
echo $slider["slider_link"];
echo $slider["slider_description"];
}

Resources