Filter posts by custom field('country')
-
Hello,
I’ve been trying to filter posts displayed on one page by a custom field named ‘country’. I’m using Ultimate Member plugin and I managed to retrieve the data from the database. Currently I’m having difficulty with filtering posts by country, for example on a UK page only posts from UK citizens would be displayed. This is the code I’m using:
<?php
um_fetch_user(um_profile_id() );
if (um_user(‘country’) == ‘Spain’ ) {
if ( have_posts() ) :
// Start the Loop.while ( have_posts() ) : the_post();
//Post format template
get_template_part( ‘page-parts/post-content-small’ );
get_template_part( ‘page-parts/posts-social-share’ );
}
?>With this code I get an error. Should I use something else? I want to enable to filter posts by country, so that even is someone is from France he/she can still filter posts by country and see posts only from the UK/Spain etc.
Thank you for your help
David
- The topic ‘Filter posts by custom field('country')’ is closed to new replies.