Custom POST type with custom taxonomy not work properly

I wrote archive template cor custom post type with custom taxonomy.

It works on my home PC with xampp php 5.5

But its not working on Apache with php 7 (my office pc).

I searched a lot in the internet. Everyone suggested what i already did.

Here is the snippet:

remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'wdm_do_custom_loop' );

$product_type = get_post_type();

if($product_type = "our_products" || $product_type = "our_services") {



    function wdm_do_custom_loop(){

        $queried_object = get_queried_object();
        $term_id = $queried_object->term_id;
        $term_meta = get_term($term_id);
        $custom_category = $term_meta->name;
        //print_r($custom_category);

    $output = '';
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    if($product_type == "our_products"){
        $args = array(
                    'post_type' => 'our_products',
                    'post_status' => 'publish',
                    'posts_per_page' => -1,
                    'tax_query' => array(
                        array(
                            'taxonomy' => 'product_categories',
                            'field' => 'name',
                            'terms' => $custom_category
                        )
                    )
                );
    } else {
        $args = array(
                    'post_type' => 'our_services',
                    'post_status' => 'publish',
                    'posts_per_page' => -1,
                    'tax_query' => array(
                        array(
                            'taxonomy' => 'service_categories',
                            'field' => 'name',
                            'terms' => $custom_category
                        )
                    )
                );

    }
    $loop = new WP_Query($args);    

    if ($loop->have_posts()) :

        while ($loop->have_posts()) : $loop->the_post();    

            $post_type_name = $loop->query['post_type'];     print_r($post_type_name);

            $id = get_the_ID();
            $title = get_the_title($id);
            $content = get_the_excerpt($id);
            $product_link = get_the_permalink($id);
            $thumb_image = get_the_post_thumbnail( $id, 'full' );   

            $images = acf_photo_gallery( 'image_upload', $id );
            $product_images = '';
            if ( $post_type_name== "our_products" ) {
                foreach ( $images as $image ) {
                    $product_images .= '<div id="product-slideshow"><div class="flexslider loading"><ul class="slides"><li><figure><a href="'.$product_link.'"><img src="'.$image['full_image_url'].'"></a></figure></li></ul></div></div>';
                }
            }
            if ( $post_type_name== "our_services" ) {
                $product_images .= '<figure class="text-center service-thumb"><a href="'.$product_link.'">'.$thumb_image.'</a></figure>';
            }

            $output .= '<div class="col col-xs-12 col-sm-6 product-list">
                        <div class="product-list-wrap pull-left full-width">
                            <div id="product-slideshow" class="col col-xs-12 col-sm-4">                         
                                '.$product_images.'                             
                            </div>
                            <div class="col col-xs-12 col-sm-8">
                                <h4 class="title-with-bg"><a href="'.$product_link.'">'.$title.'</a></h4>
                                <p>'.$content.'</p>
                            </div>
                        </div>                      
                    </div>';
        endwhile;
        $output .= '<div class="pagination full-width pull-left">'.wp_pagenavi(array('query' => $loop, 'echo'=>false)).'</div>';
    endif; 
    wp_reset_postdata();
    wp_reset_query();


    echo $output;

    }
}  else {

    add_action( 'genesis_loop', 'genesis_do_loop' );

}
genesis();

I print $loop data. but it showing no posts under specific taxonomy with and post type.

But its working properly on my home PC.

Any suggestion??

Read more here: Custom POST type with custom taxonomy not work properly

Leave a Reply

Your email address will not be published. Required fields are marked *