0

我正在尝试按用户 ID 查询帖子。在这种情况下,用户 id 将是另一篇文章的作者。

我确实尝试了以下方法,但是没有得到“作者论点”。

$author_id = $post->post_author;

$author_query_id = array('author='. $author_id, 'showposts' => '1', 'post_type'=> 'bedrijven', 'post_status' => 'any');
$author_posts_id = new WP_Query($author_query_id);

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


if (get_field('standplaats')) { ?>
<div class="fieldje field-3"><p>
        <span>Standplaats: <?php echo the_field('standplaats'); ?></span>
    </p></div>
 <?php  } 
 endwhile; 

我得到的用户 ID 是正确的(在 $author_id 中捕获)。然而,在查询中,它只查询帖子类型“Bedrijven”的最后一篇帖子,无论作者是谁。

知道为什么这不起作用吗?

谢谢!

4

3 回答 3

3

您的数组格式不正确。

$author_query_id = array('author' => $author_id, 'showposts' => '1', 'post_type'=> 'bedrijven', 'post_status' => 'any');

=从你的author钥匙上删除了。

我确定您已经看过下面的WP_Query 文档,但这里有一个链接可以在将来提供帮助,以防万一。

于 2014-01-13T16:10:49.497 回答
1

改用这个:

$author_query_id = array('author'=> $author_id, 'showposts' => '1', 'post_type'=> 'bedrijven', 'post_status' => 'any');
于 2014-01-13T16:09:05.280 回答
0

使用此代码:

<?php

$args = array(
'post_type' => 'bedrijven',
'post_status' => 'publish',
'author'        =>  $current_user->ID,
'orderby'       =>  'post_date',
'order'         =>  'ASC',
'posts_per_page' => 1
);


$author_query = new WP_Query( $args ); 

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

$standplaats = get_field('your_field');

if ($standplaats) { ?>

<div class="fieldje field-3">
<p>
<span>Standplaats: <?php echo $standplaats ; ?></span>
</p>
</div>

<?php  }  endwhile; ?>
于 2019-03-24T06:44:11.433 回答