Not Able to List CPT Based on Taxonomy Term

Check this code: <?php $custom_terms = wp_get_post_terms($post->ID, ‘service_tax’); $count = count($custom_terms); if ( $count > 0 ) { foreach($custom_terms as $custom_term) { $args = array(‘post_type’ => ‘services_cpt’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘service_tax’, ‘field’ => ‘slug’, ‘terms’ => $custom_term ), ), ); $loop = new WP_Query($args); if($loop->have_posts()) { echo ‘<div class=”col-md-4″>’; echo ‘<a class=”item-box” … Read more

Code to add template to page

locate_template function searches your current theme’s folder for template name(s). If your templates are in a root folder of your theme, use: $template = locate_template( ‘member-content-template.php’ ); otherwise, precede the name of a template with subfolder’s name ( no slash in front ): $template = locate_template( ‘templates/member-content-template.php’ ); To load a template ( if found … Read more

call a function when insert and update a custom post type

This is the original answer but it is little faulty, look below for the updated You can use following approach. The my_action_updated_post_meta is executed after the post insert or update is done: // define the updated_post_meta callback function my_action_updated_post_meta( $array, $int, $int ) { global $post; // see your updated post print_r($post); // make your … Read more

Plugin or Custom Page Type

First of all, keep it in your mind that WordPress convention says theme is only for presentation and plugin is for functionality. So that means if you need to initiate any functionality you should do that in plugin and when you represent the data visually in frontend you need to do it with theme. Now … Read more

How to pass a more variable with page/subpage in Wordprees URL?

function add_custom_query_var( $vars ){ $vars[] = “q”; return $vars; } add_filter( ‘query_vars’, ‘add_custom_query_var’ ); mydomain/how-we-work/our-process/?q=more-value You can handle it with get_query_var( ‘q’ ); Edit1: If you want to use with ‘SEO URL’ you need to add_rewrite_rule function add_rewrites(){ add_rewrite_rule( ‘^how-we-work/our-process/([^/]*)/?’, ‘index.php?pagename=how-we-work/our-process&q=$matches[2]’, ‘top’ ); } add_action( ‘init’, ‘add_rewrites’ );