WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wp_query with multiple fields not working (2 posts)

  1. Topher
    Member
    Posted 2 years ago #

    I have a custom content type called sportpages. It has fields called ecpt_link and ecpt_season. Link is a checkbox and season is a select box.

    I have one post with link set to "on" and a season of "Fall".

    Using wp_query this works to get that one:

    $args = array(
            'post_type' => 'sportpages'
            ,'post_status' => 'publish'
            ,'posts_per_page' => 1000
            ,'meta_key' => 'ecpt_link'
            ,'meta_value' => 'on'
        );

    This also worked to get that one:

    $args = array(
            'post_type' => 'sportpages'
            ,'post_status' => 'publish'
            ,'posts_per_page' => 1000
            ,'meta_key' => 'ecpt_season'
            ,'meta_value' => 'Fall'
        );

    This however gets ALL posts, ignoring everything in meta_query:

    $args = array(
            'post_type' => 'sportpages'
            ,'post_status' => 'publish'
            ,'posts_per_page' => 1000
            ,'meta_query' => array(
                array(
                    'meta_key' => 'ecpt_link'
                    ,'meta_value' => 'on'
                    ,'compare' => '='
                )
                ,array(
                    'meta_key' => 'ecpt_season'
                    ,'meta_value' => 'Fall'
                    ,'compare' => '='
                )
            )
        );

    I've tried it without the comparison operators as well. What am I missing?

  2. Topher
    Member
    Posted 2 years ago #

    I figured it out.

    Old code:

    array(
                    'meta_key' => 'ecpt_link'
                    ,'meta_value' => 'on'
                    ,'compare' => '='
                )

    new code:

    array(
                    'key' => 'ecpt_link'
                    ,'value' => 'on'
                )

    No metas in the meta_query.

Topic Closed

This topic has been closed to new replies.

About this Topic