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(); ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🚀 ACF & ACF PRO 6.0.7 are now available.
— Advanced Custom Fields (@wp_acf) January 18, 2023
✨This release contains bug fixes and improvements while we continue to work on the next major release of ACF.https://t.co/wQgAOpwmUI
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.