From pre_get_posts
in Codex:
Identifying Target Queries
When using pre_get_posts, be aware of the query you are changing. One useful function is is_main_query(), which can help you ensure that the query you are modifying is only the main query. Use it in combination with other conditional tags to only alter the main query on the pages you want.
pre_get_posts
is executed for every query on a page, which includes the query that loads your menu items, so you need to check if $query->is_main_query()
before you modify it, otherwise you’ll apply your query modifications to other queries.
Related Posts:
- Get main parent category for post (WordPress/Advanced Custom Fields)
- get_category only returning details for ‘uncategorized’
- How do I edit the terms output args or array data?
- Add a product category to a specific product via a button
- Nested Queries of decreasing specificity
- List sub categories and corresponding posts of a parent category
- Add a “custom field” to a category that can be retrieved when viewing the category page with get_post_meta
- Change category thumbnail size
- Allow two posts (from different categories) to have the same slug
- Dropdown category field inside repeatable metabox
- Get nice name of category from slug (remove dashes of category)
- Display Visual Composer shortcode if a post belongs in specific categories
- ACF: Display Google Map in frontend issues
- Bootstrap 4 Carosuel with ACF Repeater field
- Child-Theme Category View with modified permalinks (%category% removed)
- How to display acf field values from home page on all pages?
- ACF Taxonomy field values not select in backend
- admin panel – How to remove “delete” button from category editing page
- Set ACF on order during checkout
- Category Page Displaying all Pages
- Get parent category name when only child category is applied to a product
- If Statement is Ignored?
- Use WPQuery to match to specific repeater row in post
- Query on a repeater date (acf)
- How to move a post from one category to another
- How to enable HTML tags in category description without breaking the category page
- Multiple Tag Filtering
- ACF values to Script with auto refresh
- ACF relationship on user profile page used for allowed access
- ACF – Can’t get custom post type by taxonomy
- Trying to show the category of a post in the post display
- Advance custom fields variable with if statement & Function
- ElseIf Statement with ACF Group field
- Create category after theme setup and modify the default one
- Link to index.php from home.php?
- How does Permalink work with the AMP plugin after Removing Parent Permalink Catalog from Posts
- Advanced Custom Forms PHP formatting for do_shortcode
- How to Link to category titles if it is in the single post content?
- Possible to edit custom date field and display?
- Polylang and template files
- Get field value and use as variable in php
- Place product field value as variable in php
- How can i show specific Category List?
- ACF Gallery field images donwload
- Notice: Undefined variable
- ACF – Get ID of relationship field in flexible content
- Hide a specific category title from displaying on site
- How to show category just on specific pages?
- ACF under category name in shop page [closed]
- Show subcategory name selected in specific category woocoommerce
- get_template_part() not working with Advanced Custom Fields plugin
- List all ACF field values across every post on one page
- Get list of posts from attachment
- Javascript Tab Gallery with Advanced Custom Fields
- How to output values from a loop into a javascript array
- Pulling Products from an API
- How to filter specific element of an array in wordpress/php?
- Return to the beginning of the results of a for loop
- PHP/CSS: Shortcode won’t display correctly, and only displays in the head (before content)
- Exclude category and post from loop in custom category.php
- ACF background-color per post in a WordPress loop
- Admin backend, show post from a category and exclude the posts from subcategories
- How can I copy an ACF field to AIOSEO field? [closed]
- Scheduling a post using publish date from a custom field. Resulting post is set as published in the future instead of scheduled
- Make sticky post with FacetWP
- Populate Posts based on category selected using AJAX that means without page refresh
- All categories options or All categories not Populating
- random woocommerce categories are not showing when count enabled?
- Exclude a category slug on pagination
- Customizing the output of the archive and category widget without altering the original behavior of the widget
- Custom content using in_category
- Generate a radius search of custom post type locations
- How to Retrieve All Category Images on Front-End
- WooCommerce Custom Tab with ACF Repeater Field
- Ordering / grouping posts by datepicker ACF
- PHP for loop not working as intended
- Displaying 3 Category Posts differently
- Position a repeated article blocks
- Is there a reason why my wordpress PHP page isn’t loading into my PHP template
- ACF + WP + Slick Slider Repeater Slide Group PHP not Displaying [closed]
- PHP drop down menu for my get_category child of
- Short code into PHP
- PHP get_category() function redeclared
- Display a single row from nested array of custom field data
- Code works on page-example.php by not category-example.php
- Need Quick Help With Product Category Page
- List categories assigned to a post
- get_category display only 1
- Unable to get Post Category Name and URL
- Else if Statement for Advanced Custom Fields [closed]
- How to list categories by page id in wordpress
- ACF Images If/else
- Need to adjust condition to say if I’m pulling categories from a post, to pull only the first one
- WordPress using get_term to retreive slug not working as expected
- How to add style in functions.php depending on conditions?
- Showing the project type in HREF
- How do I display Category titles on a WP Page?
- Rearrange get_categories array compared to another array
- Front end post submissions do not get submitted in the category
- problem with category menu, it doesn’t want to show link