Answer the question
In order to leave comments, you need to log in
Creating a loop within a loop with different $args?
I have a similar design:
$company_pname = wp_get_post_categories( $post->ID, array('fields' => 'all') );
foreach( $company_pname as $cat_comp ){
$args = array( 'post_type' => 'post-pharmacy', 'posts_per_page' => -1, 'name' => $cat_comp->slug);
$cat_comp = get_posts( $args );
foreach( $cat_comp as $post ){ setup_postdata($post);
$post_slug = $post->post_name;
/* Мой контент, выводимые записи */
}
}
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug'
)
)
);
$first_query = new WP_Query($args);
while ($first_query->have_posts()) :
// initialization for $inner_args & backup the current global $post
$inner_args = array(
'post_type' => 'post-pharmacy',
'posts_per_page' => -1,
'name' => $first_query
);
$inner_query = new WP_Query($inner_args);
while ($inner_query->have_posts()) :
/* Мой контент, выводимые записи */
endwhile;
// restore the global $post from the previously created backup
endwhile;
Answer the question
In order to leave comments, you need to log in
First, you make 1 request and save the required result, for example, into an array. After that don't forget to do wp_reset_postdata();
Then run foreach on the array and generate the necessary wp_query queries, remembering to use wp_reset_postdata();
This is the answer to your question. I would advise how to organize the algorithm itself in a different way. Since this one will be very resource intensive.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question