• Resolved Miguel

    (@teledirigido)


    Hi there.

    Firstly, this plugin is so amazing. I just have a question:

    How I can filter by a dropdown option on the WP_QUERY?

    Example: I have a people post_type with a dropdown menu with a city dropdown field, and I want to filter by those field.

    // Showing people
    $args = array(
     'post_type' => 'people',
     'meta_key' => 'city',
     'meta_query' => array(
    	array(
    	 'key' => 'city',
    	 'value' => 'Nelson',
    	 'compare' => 'IN',
    	)
     )
    );

    As “city” is a “dropdown field” and not a “text custom field” i can’t really filter it, unless I change “city” for a custom taxonomy.

    Thanksss

    https://www.ads-software.com/plugins/magic-fields-2/

Viewing 1 replies (of 1 total)
  • Thread Starter Miguel

    (@teledirigido)

    As “city” seems like a taxonomy field rather a “custom field” so I changed my query into this:

    // Showing people
    $args = array(
     'post_type' => 'people',
     'tax_query' => array(
      'relation' => 'AND',
       array(
        'taxonomy' => 'city',
        'field' => 'slug',
        'terms' => array( 'nelson','otago-southland'),
        'include_children' => false,
        'operator' => 'IN'
        )
       ),
      );

    So now I can filter my post with no probs.

    Hope this helps to someone.

Viewing 1 replies (of 1 total)
  • The topic ‘Filter by dropdown custom field on WP_QUERY ?’ is closed to new replies.