• Hello there!

    i need to query author in meta_query and not from author arg.

    sample:

    $search_args = array(
        'post_type' => 'custom_post_type',
        'post_status' => array('publish'), 
        'posts_per_page' => -1,
        'meta_query' => array(
            'relation' => 'OR',
            array(
                'relation' => 'AND',
                array(
                    'key'     => 'author',
                    'value'   => '1234',
                    'compare' => '=',
                ),
                array(
                    'key'     => 'custom_key',
                    'value'   => 'the_key',
                    'compare' => '=',
                ),
            ),
            array(
                'relation' => 'AND',
                array(
                    'key'     => 'author',
                    'value'   => '4321',
                    'compare' => '=',
                ),
                array(
                    'key'     => 'custom_key',
                    'value'   => 'the_key',
                    'compare' => '=',
                ),
            ),
        ),
    );
    • This topic was modified 6 years, 6 months ago by The Three.
Viewing 3 replies - 1 through 3 (of 3 total)
  • What is your question?
    The query you wrote says to find all(-1) published entries of ‘custom_post_type’ that have either ( post-meta keyed ‘author’ equal to ‘1234’(string) and post-meta keyed ‘custom_key’ equal ‘the_key’ ) or ( post-meta keyed ‘author’ equal to ‘4321’(string) and post-meta keyed ‘custom_key’ equal ‘the_key’ ).

    If that’s not what you wanted, can you be more specific?

    Thread Starter The Three

    (@3wwwgr)

    @joyously hello there!

    lets say that i have two custom meta keys
    meta key #1: _phone
    meta key #2: _surname

    so i want to query the posts from author with ID 1234 AND meta key ‘_phone’ with value ‘xxxxxxxx’
    OR
    posts from author with ID 4321 AND meta key ‘_surname’ with value ‘xxxxxxx’

    but as far as i know, author’s ID does not exists in custom meta fields.

    • This reply was modified 6 years, 6 months ago by The Three.

    Are your meta data in the user meta table or in the post meta table?
    You might have to do a query on the user table to find the correct author and then use that in the query on the post table.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘WP_Query – Author in meta_query’ is closed to new replies.