Skip Navigation

[Resolved] show user (author) profile with published posts

This support ticket is created 5 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

Tagged: 

This topic contains 34 replies, has 4 voices.

Last updated by Nigel 5 years ago.

Assisted by: Nigel.

Author
Posts
#1227097

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

But this is the same role where you *do* want the posts to appear on their author archive?

So your condition would be something like:

if ( !is_admin() && $query->is_archive() && !$query->is_author )

That would run your code to remove posts by users with the specified role on all archive pages except for author archives, which I think it what you need.

As I mentioned in my previous reply your condition for the page = 31 doesn't do anything because if the previous condition was met we've already established we are on an archive page, not a static page which may or may not have an id of 31.

#1227115

I have two custom roles:

- PRODUCATOR NEAUTORIZAT: they can create ANUNTURI posts through the cred form but their posts are only shown on their own account page (ID 31 - a view is inserted that lists the posts of that author). This is just a temporaty role. The account page and the authors archive is not the same. The account page is for the logged in users to manage their content, the authors archive is for the public. That's why the exception.

- PRODUCATOR: Their posts should be shown in the author archive and every view where I query for the ANUNTURI post type.

So basically in every view where I query ANUNTURI post I want to show just the posts of PRODUCATOR role. But when on the account page (id 31) I need to show posts of every role.

This problematic function (remove_unvetted_authors) causes problems in every anunturi view, except the author archive. In author archives the view shows only the posts of authors with PRODUCATOR role. But all the other views show every post created by anybody.

#1227171

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

OK, then in that case it sounds like for any query of ANUNTORI posts, unless we are on page 31, posts by authors with the role PRODUCATOR NEAUTORIZAT should be excluded.

So your code for that would be updated to:

add_filter('pre_get_posts', 'remove_unvetted_authors');
function remove_unvetted_authors($query)
{
    if (!is_admin() && !is_page(31)) {

        $post_type = $query->get('post_type');

        if (isset($post_type) && $post_type == 'anunturi') {
            $user_ids = get_users([
                'role' => 'producator_neautorizat',
                'fields' => 'ID',
            ]);

            $query->set('author__not_in', $user_ids);
        }

    }

    return $query;
}

Can you test that?

#1227182

Yes, it seems that it is working now. THANK YOU!!!

I see that you used add_fliter instead of add_action, you removed the is_archive which is redundant and you limited it to the anunturi post type. Can you please explain me what caused the problem in my old function? The add_action?

#1227726

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Sorry, that was a typo, it should be add_action not add_filter.

The problem with your old function was simply that the logic was wrong. Once I understood what you required it was just a question of thinking through the tests for how to implement it.

In words the logic is effectively "except for page 31, everywhere on the frontend where anunturi posts are displayed, hide those from unauthorised authors".

The code is fairly simple, hopefully you can follow it.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.