0

I am using post widget in elementor pro. Idea is to show all posts by a specific custom post type. Now, I want to apply also some filters in particular I want to show only posts in a particular status (ie, "draft") and those created ("post author") by the user logged in.

I have been able to create a query for status and pass the query id (my_query_by_post_status), this is the case:

add_action( 'elementor/query/my_query_by_post_status', function( $query ) {
$query->set( 'post_status', ['draft'] );
}   );

But I don't know how to add a condition to say "only for author same as the current user logged in".

Can anybody help me in this? I really appreciate and thank you in advance. Mario.

1 Answer 1

0

get current user id using get_current_user_id() (will return 0 if no user logged in)

$current_user = get_current_user_id();

if($current_user != 0){
  $query->set( 'author', [$current_user] );
}

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.