-
MartinM
Hi,
is there a way I can use Query Loop on a specific page to show posts for a given post type e.g. “Project” and only those where the currently logged in user is the author?
I’ve tried Query Loop > Select post type > Project > Authors > Current post author (but I’m still getting all posts from all authors, so that’s probably not the right way to do it…)
Thank you for your help π
-
Hi there,
There’s no such built-in option in the query loop block, so please remove the author parameter from the query loop block first.
However, you can try this method:
1. Add an additional CSS class to the Grid block of the query loop block, eg,
my-articles
.
https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/2. Add this PHP code:
add_filter('generateblocks_query_loop_args', function ($query_args, $attributes) { if ( !empty($attributes['className']) && strpos($attributes['className'], 'my-articles') !== false && is_user_logged_in() ) { $current_user = wp_get_current_user(); $query_args['author'] = $current_user->ID; } return $query_args; }, 10, 2);
Adding PHP: https://docs.generatepress.com/article/adding-php/
Let me know if this helps!
-
MartinM
Hi, Ying,
it works like a charm, you’re the queen of customer support,
thank you π
-
Haha I’m the only female in GP’s tech support team, I guess that made me the queen lol π
- You must be logged in to reply to this topic.