get_query_vars always retruns empty value

In my test scenario I use the original twentytwentyone theme with no plugins activated. My code is placed at the end of functions.php. This is the problem. Your code is running as soon as functions.php is loaded, which is before the query vars are populated. If you use get_query_var() inside an action hook that runs … Read more

add_post_type_support but for front_page only

If you want to enable excerpt for specific page, then you can add some conditions to narrow down. For check “front page id” you can use get_option(‘page_on_front’); in admin area. (is_front_page() should not work here) global $pagenow; // check current screen is edit page if ( $pagenow == ‘post.php’ ) { $fron_page_id = get_option(‘page_on_front’); $current_page … Read more

Sorting a custom post type in pre_get_posts

You can add a filter on posts_clauses to; left join additional columns for each meta filter add order by clause base on those column values. Something like below should work, assuming your meta key is start_date and the value has the actual date format Y-m-d and your post type is talks add_filter( ‘posts_clauses’, function ($clauses, … Read more

ajax problems on loading page [closed]

I finally find out the problem. The problem is when I load wordpress page a builtin ajax call is started. and this part of my code: jQuery(document).ajaxStart(function() { jQuery( “#step-general” ).hide(); jQuery( “.pelak-loader” ).show(); }).ajaxSuccess(function() { jQuery( “.pelak-loader” ).hide(); }); is used on loading page. I use if conditional in ajaxStart to limit its border!

Custom plugin with shortcode not working

add_shortcode(‘myCustomShortcode’, ‘this_particular_function’); As soon as I looked at my code this morning I realized I was trying to pass the function name ([this_particular_function]) as the shortcode, not the shortcode name ([myCustomShortcode]). I overlooked this SO many times yesterday trying to look for some complex answer! I am smacking my head on the desk. Everything works … Read more

Can I associate a custom post type with another custom post type?

Yes, you can. You would need to add a custom field that would store the ID of other post type. I would recommend using a select list. You could try something along these lines: add_action( ‘add_meta_boxes’, ‘wpse_143600_add_box’ ); add_action( ‘save_post’, ‘143600_save_box’ ); //create the metabox function wpse_143600_add_box() { add_meta_box( ‘related_testimonial’, __( ‘Testimonails’, ‘wpse_143600_translation’ ), ‘wpse_143600_testimonial_box’, … Read more