0

I have a front-end form which stores some data related to that post and adds that post to their favorite posts when the user clicks on it. So now my concern is when the user clicks on the favorite posts template it should only see their favorite post.

$args = array('posts_per_page' => 20, 'paged' => $paged, 'post_type' => 'post', 'post_status' => 'publish' );

This is my query right now. How can I modify it that it only show those post which the user mark as favorite?

add_post_meta($postid, 'favpost'.$userID, $postid);

This is how the user marks their favorite post. Can anyone guide me on how I can get my data base on post_meta?

1 Answer 1

0

change the $args to this:

$args = array(
    'posts_per_page' => 20, 
    'paged' => $paged, 
    'post_type' => 'post', 
    'post_status' => 'publish', 
    'meta_query' => array(array('key'=>'favpost'.$userID, value=>'1', 'compare' => '='))
);

That is if the post_meta value is 1 when the user select that post as it favorite, or it could also be 'true' you will have to check that value on the custom fields area of the post edit.

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.