Post count for particular term

Your query is completely wrong. You should use a proper tax_query. Also note, your query is quite expensive to run to just count posts. Set the fields paremeter to only return post ID’s. This saves up to 99.9% on resources. Just a note, the field parameter inside a tax_query is important. The valid values are … Read more

Custom Post Type to Plugin

i agree with the other answers, but neither addressed flushing the re-write rules. If you don’t add this, it will confuse your users when they activate the plugin and still can’t access the custom postypes on the front. The other problem you’re going to have is that LOTS of people will use testimonials so if … Read more

How to hide home title on pages and posts?

If I follow what you’re explaining correctly, try adding a document title filter to the functions.php theme file. (NB: setting to only change post and pages. Search, Archive, etc, will keep original title. You can always modify accordingly.) *** EDIT: added a filter for older themes that uses wp_title. add_filter(‘wp_title’, set_custom_page_title, 99999); //NB:backward compatibility with … Read more

CPT Template Option to Top

You could hook into theme_{$post_type}_templates and add an identical “default” option at the end: add_action(‘theme_page_templates’, ‘wpse_296283_theme_page_templates’); function wpse_296283_theme_page_templates($post_templates){ $post_templates[‘default’] = “Default Template”; return $post_templates; } Then you’d hide the first one with CSS: add_action(‘admin_head’ ‘wpse_296283_admin_head’); function wpse_296283_admin_head(){ ?> <style>#page_template option:first-child {display: none;}</style> <?php }

Adding custom shortcode to page leads to page without styling

Shortcodes need to return their values, but the_content() echoes the post content. So you have two options. First is to capture all output and then return it at the end: ob_start(); // Start capturing output; while( $loop->have_posts() ) { $loop->the_post(); the_content(); }; wp_reset_postdata(); return ob_get_clean(); // Return captured output; That will be the cleanest way … Read more