Support

Account

Home Forums General Issues Pulling Custom Post Data into a Loop – using it throughout the loop Reply To: Pulling Custom Post Data into a Loop – using it throughout the loop

  • it’s hard for me to figure out what you’re doing with the way the code is all chucked up. Can you post all of your code in one block.

    Also, why are you doing this? category.php already pulls the posts from the current category, so this seems to be an extra query doing the same thing that is already done for you. If this is to just filter out posts to just get posts of the post type then this should be done with a pre_get_posts filter. The reason I ask is that your using wp_reset_postdata() and because you have a nested custom query this is probably not working the way you think it’s working.

    
    $cat = get_queried_object();
    				$cat_id = $cat->cat_ID;
    				$custom_query = new WP_Query( 
    					array( 
    						'post_type' => array('post', 'products'),
    						'cat' => $cat_id
    					)
    				);
    				if ( $custom_query->have_posts() ) : while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>