문제

I'm trying to query post by the user id. The user id in this case will be the author of another post.

I did try the following, however it's not getting the 'author argument'.

$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; 

The user id I'm getting is correct (captured in $author_id). However in the query it just queries the last post of the post type 'Bedrijven', no matter who the author is.

Any idea why this is not working?

Thanks!

도움이 되었습니까?

해결책

Your array is formatted incorrectly.

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

I removed the = from your author key.

I'm sure you've seen the WP_Query documents below, but here is a link to help in the future, just in case.

다른 팁

use this instead:

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

Use This Code:

<?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; ?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top