admin管理员组文章数量:1289866
So I am building a query, and I wanted to see if someone can assist me on a special attempt to infuse two queries.
So here is what I'm attempting to do:
Check if we have any relationship posts, which I can return either an
array of IDs
or anarray of WP_Post objects
.I want to showcase the relationship posts first if they are and then showcase the remaining wp_query posts.
Here is what I'm working with:
Original:
$args = [
'post_type' => ['work', Report_Type::CPT_NAME],
'posts_per_page' => 4,
'post_status' => ['publish'],
];
$query = new WP_Query($args);
Then I'm looping through using a template as shown below:
if ($query->have_posts()) {
ob_start();
get_template_part('template-parts/blocks/work-expertise-filter/work-items-template', null, ['query' => $query]);
$content = ob_get_contents();
ob_end_clean();
wp_reset_postdata();
}
So let's say, that I have get_field('featured_posts')
which returns back an ARRAY of IDs (I can check it to ARRAY of WP_Post objects if needed).
This is our return: array(2) { [0]=> int(14244) [1]=> int(14566) } array(4) {
So I attemped to do something like this:
$args = [
'post_type' => ['work', Report_Type::CPT_NAME],
'posts_per_page' => 4,
'post_status' => ['publish'],
];
$query = new WP_Query($args);
$all_ids = [];
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$all_ids[] = array_merge($query->post->ID, get_field('featured_posts'));
}
wp_reset_postdata();
}
$all_ids = array_unique($all_ids);
$args = [
'post__in' => $all_ids
];
$the_query = new WP_Query($args);
But I'm getting no response back, it's basically: object(WP_Query)#1853 (50) { [“query”]=> array(1) { [“post__in”]=> array(1) { [0]=> NULL } } [“query_vars”]=> array(63) { [“post__in”]=> array(1) { [0]=> NULL }
If someone could help me with a query, it would be much appreciated!
本文标签: wp queryCombine relationship posts with existing wpquery
版权声明:本文标题:wp query - Combine relationship posts with existing wp_query 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741409322a2377136.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论