简体   繁体   中英

Get the author's posts in spacific category

i want to get the author's posts in spacific category and display it in author page I tried this code and it didn't work, what is the problem? my code :

<?php
$url= get_site_url();
$author_id = get_the_author_meta('ID');
$args = array(
    'author' => $author_id,
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'cat' => '161,181,157',
            'post_count' => '3',
        ),
    ),
);
$query = new WP_Query( $args );
while ( $query->have_posts() ) {
    $query->the_post();
    $postid = get_the_ID();
    echo '<a href='. $url .'?p='. $postid .'>' . get_the_title() . '</a>';
}
?>

Try the below code.

$url = get_site_url();
$author_id = get_the_author_meta('ID');
$args = array(
    'author' => $author_id,
    'tax_query' => array(
        array(
            'taxonomy' => 'category',
            'field'    => 'term_id',
            'terms'    => array(161,181,157)
            
        ),
    ),
);
$query = new WP_Query( $args );
while ( $query->have_posts() ) {
    $query->the_post();
    $postid = get_the_ID();
    echo '<a href='. $url .'?p='. $postid .'>' . get_the_title() . '</a>';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM