I'm looking for a way to check if (whilst outside the loop) the current user.. 1. is logged in 2. has a post published 3. their post has any term/terms from a custom taxonomy
I have this so far...
<?php if (( 1 == count_user_posts( get_current_user_id(), "post" ) && is_user_logged_in() ) { ?>
blah blah
<?php } ?>
I'm just wildly guessing here but could I use if( has_term( '', 'custom-taxonomy' ) )
? but that's for use inside the loop.
I'm looking for a way to check if (whilst outside the loop) the current user.. 1. is logged in 2. has a post published 3. their post has any term/terms from a custom taxonomy
I have this so far...
<?php if (( 1 == count_user_posts( get_current_user_id(), "post" ) && is_user_logged_in() ) { ?>
blah blah
<?php } ?>
I'm just wildly guessing here but could I use if( has_term( '', 'custom-taxonomy' ) )
? but that's for use inside the loop.
1 Answer
Reset to default 1This can be done using WP_Query using author and tax_query.
Something like this:
$args = array(
'post_type' => 'post',
'author' => get_current_user_id(),
'tax_query' => array(
array(
'taxonomy' => 'custom-taxonomy',
'operator' => 'EXISTS'
),
),
);
$query = new WP_Query( $args );
And then check if posts are returned through this query.
Please note that this code is not tried or tested and may contain syntax errors.