0

I'm using wti_like plugin and this is how i get the number(count) of post liked by the author

// Get the author object
$author = get_user_by( 'slug', get_query_var( 'author_name' ) );

// Get the post ids liked by the author
$like_ids = $wpdb->get_var("SELECT SUM(value) FROM {$wpdb->prefix}wti_like_post
            WHERE user_id = {$author->ID} AND value > 0
            GROUP BY post_id ORDER BY SUM(value) DESC");
?>

echo (int)$like_count;

How can i query the posts liked by the author and use my post format to display them in my author.php template?

ie:

get_header(); ?>

    <section id="primary" class="site-content"> 

        <div id="content" role="main"
< ?
$args = array(
  //QUERY OPTIONS GOES HERE//
);

$wp_query->query( $args ); ?>


        <?php if ( have_posts() ) : ? >

1 Answer 1

0

Your query would be something like:

$post_ids = $wpdb->get_col( "SELECT DISTINCT post_id FROM {$wpdb->prefix}wti_like_post WHERE user_id = {$author->ID}" );

Then you can pass that array of post IDs as the post__in argument of WP_Query:

$args = array(
    'posts_per_page' => -1,
    'post__in' => $post_ids
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.