How to filter a meta query where auther == user?

Hi,
i have a custom post type named projects. those projects are created in the frontend by registered users, so each project has a valid author.

now i have created a loop and i want to how to the actualy user only projects that are created by him (so where this user equals author)

On this page (Dynamic Data – Bricks Academy) bricks offers for an author only dynamic data {author_name} which is equal to “{wp_user_frist_name} {wp_user_last_name}” when i put those variables in a regular textfield.

but when i try to filter the loop by this meta_query its not working.

so my question is:
what can i do to show to a user only projects that are created by himself?

Here is a screenshot that shows what i mean:

Please can somebody help?

I don’t know why - but author meta just doesn’t work. You can add author_email / author_name - to a basic text in a query loop - and it shows… but use it in the meta and it returns nothing, in any combination I’ve tried.

The only fix I found was to add some code in functions.php

add_filter( 'bricks/posts/query_vars', function( $query_vars, $settings, $element_id ) {
    if ( $element_id == 'xxxxxx' && is_user_logged_in() ) {
        $query_vars['post_type'] = [ 'post' ];
        $query_vars['author'] = get_current_user_id();
    }
    return $query_vars;
}, 10, 3 );

Replace xxxxxx with the ID of your bricks QUERY element - just the last bit. e.g. if it’s #brxe-abcdef
Then use just ‘abcdef’.

Found here: Query Loop to only show current users posts? - #6 by bricksultimate

1 Like

@digismith thank you for your help. I will try to do it this way. I leave a feedback as soon as i solved it the way you mentioned.

@digismith so it worked that way perfectly. thank you