Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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