0

I want to unpublish profiles of users that doesn't have all extra fields that I've created filled.

I use a custom meta_query in a user taxonomy in order to filter those authors, and that work, but it doesn't in author templates.

function unpublish_not_full_authors( $query ) {
    if ( $query->is_author() && $query->is_main_query() ) {
            // your code to set $current_user_name here
            $query->set( 'meta_query', array(
                'relation' => 'AND',
                array(
                  'key'     => 'descripcion_breve',
                  'compare' => 'EXISTS',
                ),
                array(
                  'key'     => 'titulacion_preparador',
                  'compare' => 'EXISTS',
                ),
              )
            );
    }
}
add_action( 'pre_get_posts', 'unpublish_not_full_authors' );

EDIT TO CLARIFY:

When a users register in my site he/she gets an URL to his website: example.com/author/my_profile.

What I want is to "un-publish" this public profile until the author doesn't have filled a few fields that I've created using ACF.

  • 1
    The problem's description is still unclear to me, like: a) To un-publish something usually means to change the post status from 'publish'. b) what do you mean by a user taxonomy here? c) It's not clear what you mean by a meta query in a user taxonomy. d) What do you mean doesn't work? What kind of errors? Please elaborate. Thanks. – birgire Apr 24 '16 at 11:18
  • I don't know what you think you're doing but pre_get_posts action has nothing to do with users but posts only. You say you created extra fields, show us how you did that. – Zlatev Apr 24 '16 at 13:54
1

You're doing something like this tutorial on categorizing wordpress users, correct?

I think you should do your filtering in your theme files, not on a hook. Just add an if statement to your template file (probably author.php) that tests if your custom fields aren't empty strings, and then do whatever (404, redirect elsewhere, throw a notice...)

Unless you need to specifically have a parameter that says whether an author is public or not (e.g. you're planning to write a back-end user management GUI or something like that), hiding users through theme files should be the easiest way to this.

  • You're right, with an IF statement is easier. – Kevin Mamaqi Apr 25 '16 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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