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
- Display List Of Posts Containing a Relationship Field Value [ACF]
- Using OR conditions in meta_query for query_posts argument
- 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
- ACF datepicker meta_query Compare Dates in m/d/Y g:i a – Not in Ymd Format
- WordPress meta_query and order by custom field
- Sorting Posts by custom field
- Order posts by date and then by custom field
- Querying by taxonomy vs Querying by Custom fields Speed Comparison
- meta_query with array as value
- meta_key and meta_value not working together
- How can i make WP_Query return post image and categories?
- How add a custom posttype name using ACF field to a query post array
- Ordering Posts Type A by Custom Fields of related Post Type B
- Query Posts depends on custom field inside repeater field using acf
- Search Posts with Custom Fields as query
- Custom Post type and Custom Field WP_Query
- ACF Date Based wp_query
- exclude posts with a specific custom field and value
- Custom query based on meta key – Reduce three states to two in results?
- How to make Meta Query case sensitive?
- Any number in meta key (wp query)
- How do I run through a WordPress loop called from a filter function?
- How do I correctly set up a WP-Query to only show upcoming event-posts?
- Meta_query with multiple keys and multiple values
- WP_Query order by custom field, then randomly order some of results
- meta_query BETWEEN, but the range is stored in the custom field
- Get a list of posts with associated meta_value
- WordPress Comments sort by custom meta key
- Understanding the orderby in WP_Query?
- 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
- Order by empty custom field
- Multisite wp_query & switch_to_blog issue
- Get all fields inlcuding “ACF” (Advanced Custom Fields) columns in wp_query
- Search posts missing a particular custom field
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Merge 2 custom post type posts and taxonomy terms and sort ascending
- JSON – Create rest api endpoint for Advanced Custom Fields
- WP_QUERY with group by with custom fields
- How to order posts on each different category?
- Intiger meta value with ‘>=’ returns posts with lower value
- Query posts using less than
- Custom query filter by ACF date custom field
- Excluding posts with certain value of meta_key keeping posts without that meta_key
- Group by custom field value (start and end times)
- Query using string from custom field as array value
- How to show list of posts with custom field value (a date) that are coming soon
- Comparing 2 Decimal Numbers from custom fields and displaying posts
- Sorting posts by Multiple custom fields in defined order
- WP Query orderby ACF boolean values and ACF field value
- Optimising WP_Query with ACF Fields
- meta_query weird behaviour, static int will work, but not user data
- Woocommerce Shortcode which displays a table with product data
- WP_Query – display posts by custom field and order by another
- Excluding posts from search results page with meta query not working
- Query posts by post type, author and post meta
- Populate select list with meta values from all posts of a Custom Post Type
- Form checkbox value going to dynamic URL
- Query on a repeater date (acf)
- Query for getting posts with their custom fields data in WordPress
- Getting posts by custom field value
- How to get taxonomy image attached to a Post Type WordPress
- How to rearrange posts based on input field values added by WordPress “Advanced Custom Fields”
- WP Query with meta queries
- Query post by Category and custom file (ACF)
- Pre get posts sort by meta key returns no results if meta key does not exist
- ACF Post Object meta-query by title not ID
- From admin edit user page query either the user_nicename or username field value of the user profile being edited or viewed
- Query by meta value (add a dropdown of all values)
- ACF: using two loops, the_field returns field content from another loop
- Query by Category and Custom Field – Shortcode
- Object of class WP_Query could not be converted to int inside shortcode
- WP_Query with Pagination and orderby meta_value_num showing duplicates
- Mathematical operations on custom field values? (updated)
- WP_Query within save_post doesn’t include the item that triggered the action?
- Compare meta key separation
- Custom search (wp query by custom fields)
- Custom Search Query – include only custom fields and title
- query_posts with sorting on a custom datestamp
- Creating array to compare custom field values
- How to Order Posts by Custom Fields?
- Taxonomy related query not working
- WP_Query – order with usort by custom meta
- Display ACF object field data using Elementor Custom Query
- How do I subquery with custom meta fields?
- Use value from meta key array for use in WP_Query
- WP_Query sort by ACF date field (newest first) with blank dates first
- How to include custom fields in wordpress search
- Extend search query to search meta keys values based on search string
- WP_query shortcode inside acf Repeater breaks the repeater loop