Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
IGNACIO CANO

Error when want to show only register user posts

Hi, when I try to do this function, to show only current user posts, the action do the job, but not show ACF fields, it show a “-” instead . You can see the image below.

ERROR to show only Author posts

add_action('pre_get_posts', 'query_set_only_author' );

function query_set_only_author( $query ) {
	global $current_user, $pagenow;
		
		if( 'edit.php' == $pagenow){
 
			$query->set( 'author', $current_user->ID );
			
		}
}

Is there another way to show only current user posts?

Thanks

3 years, 11 months ago
Stefan van den Dungen Gronovius
Developer

The ACF column uses the ACF function get_value() which does get_post call on the background. This means it will also be affected by your hook. Make sure to use the is_main_query() to prevent that and only run your logic for the main query.

is_main_query()

3 years, 11 months ago
IGNACIO CANO

Excelent, it works!

3 years, 11 months ago

You must be logged in to reply to this topic.