If main_category
is a category (custom taxonomy), then you’re querying it wrong. This should go like this:
$electronics = array(
'numberposts' => -1,
'post_type' => 'article',
'main_category' => 'electronics'
);
$query_electronics = new WP_Query( $electronics );
If that’s a custom field, use meta_query
:
$electronics = array(
'numberposts' => -1,
'post_type' => 'article',
'meta_query' => array(
'key' => 'main_category',
'value' => 'electronics'
),
);
$query_electronics = new WP_Query( $electronics );
Related Posts:
- Revolution Slider Orderby Two Custom Fields
- How To Fix WP Query Returns Results But Shouldn’t?
- ACF: How to query for a given value count of an array like field? (e.g.: How many rows has a `flexible_content` field?)
- WP_Query, ACF field and array
- Wrap group of wp query posts to parent div by date/year
- Query posts filter not working
- Display all custom meta field values from the database using ACF Repeater
- Best performance for use Custom Field in WP
- Can wp_query return posts meta in a single request?
- Meta query with string starting like pattern
- compare meta_query in get_posts arguments
- How can I use order_by to order by two meta_keys without excluding posts that don’t have those keys initialized?
- Display List Of Posts Containing a Relationship Field Value [ACF]
- Function in array as arguments for WP_Query
- Using OR conditions in meta_query for query_posts argument
- WP_Query to show post from a category OR custom field
- ACF Relationship Field Search Filtering [closed]
- Sorting posts by custom date fields (non standard date format)
- Filtering a WP_Query meta_query by numeric values isn’t working
- Getting attachments by meta value
- meta_query where value is equal to given value
- ACF datepicker meta_query Compare Dates in m/d/Y g:i a – Not in Ymd Format
- Get_post() with meta_key when compare is a date
- querying with custom meta field with meta_query
- Group posts by custom field
- Order by meta_value_num DESC and meta_value ASC on WP 4.0
- WordPress meta_query and order by custom field
- getting posts and number by specific meta value in multiple meta
- How to query using a combination of custom_field values?
- Sorting Posts by custom field
- Order posts by date and then by custom field
- Query two post types and order by two different date fields
- WordPress altering my custom query, How to fix it?
- Querying by taxonomy vs Querying by Custom fields Speed Comparison
- meta_query with array as value
- query posts in functions.php and update a field
- Order by meta_key in custom post type doesn’t affect the query
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- meta_key and meta_value not working together
- How can i make WP_Query return post image and categories?
- Custom Field sort not working (WP 3.8.1)
- Advanced Custom Fields query
- Display posts if a custom field value is equal to another custom field value
- wp_query with multiple custom fields
- How add a custom posttype name using ACF field to a query post array
- Filtering posts by custom field value not working
- Minimising number of queries on a page when using Advanced Custom Fields
- Display link to taxonomy archive only if it has posts with certain custom field values
- getting posts and number by specific meta value in multiple meta
- Ordering Posts Type A by Custom Fields of related Post Type B
- Query Posts depends on custom field inside repeater field using acf
- Order Posts by meta value AND published date
- ACF Relationship + WP Template Parts
- Minimising Database Queries when using Advanced Custom Fields
- ACF – Get lowest & highest value from field
- If two first numbers exist in wp_meta_query value
- WP_Query meta_query >= date
- Search Posts with Custom Fields as query
- wp_query add arguments using array_push if variable met
- Custom Post type and Custom Field WP_Query
- Group WP_Query by meta_key date
- Get posts for which a custom field is not present, with get_posts
- Output an array of terms for a ‘tax_query’ => array()
- ACF Date Based wp_query
- Multiple taxonomy And acf filter group by
- exclude posts with a specific custom field and value
- Custom query based on meta key – Reduce three states to two in results?
- Include custom field in Ajax search WordPress
- What is the random string I am seeing when I use get_query_var?
- Add quicklink to in the Admin posts page where I can query by a meta_key
- How to make Meta Query case sensitive?
- How to Filter Posts by Custom Fields?
- Any number in meta key (wp query)
- Display custom field meta outside loop, site wide
- How do I run through a WordPress loop called from a filter function?
- How can I display a custom field from all posts and order them individually from their parent post
- Fetch Record based on meta key dates
- How do I correctly set up a WP-Query to only show upcoming event-posts?
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- Meta_query with multiple keys and multiple values
- WP_Query order by custom field, then randomly order some of results
- Orderby is working with one query but not with other
- meta_query BETWEEN, but the range is stored in the custom field
- Query custom post type with ACF Date
- Get a list of posts with associated meta_value
- WordPress Comments sort by custom meta key
- Understanding the orderby in WP_Query?
- Extend product search with meta in WooCommerce
- Is there a way to work with a specific the_field from an already queried post? [closed]
- How to list custom fields as headers and list all pages sharing that custom field under it?
- How to Union two different conditions in one WP_Query
- how to make members list directory through wordpress post custom meta key.
- Order by empty custom field
- Query posts without meta preload
- Adding multiple meta_key fields as orderby options to a WP Query via a function
- Order Custom Post Type by Custom Field Value
- Large AND OR query timing out
- Excluding pages in WP_query using ACF
- How to do a wp_query with two acf-fields, sorting on one of them
- Using Advanced Custom Field for file upload, how do I load the file url