The action hook pre_get_posts
is called well before the page template is rendered. Move add_action('pre_get_posts', 'my_pre_get_posts');
and your my_pre_get_posts()
function to your theme’s functions.php
file.
Related Posts:
- Custom Queries: Joining On Meta Values From Two Custom Post Types
- Automatically adding meta data to posts or multiple query help
- WordPress Orderby Numeric Value Not Working
- Returning a custom content types with meta values
- Linking posts together with Advanced Custom Fields “both ways”
- meta query always fails even if data is correct
- Retrieve post data via WPDB class
- What’s the equivalent of Hide From Menus on MODX on WordPress?
- Custom filter function not working with Custom post type
- WP_Query orderby and tax_query
- I am trying to hide a custom post type category to logged in users with Pre_Get_Posts
- Displaying Posts from Custom Post Types
- Different Ways to Query Custom Post Types?
- Importing Data from a Non-WordPress database, into WP
- Getting thumbnails of a custom posts featured images in a page-templates metabox
- How to organise this data within WordPress
- List Taxonomies: Don’t list taxonomy if it has no post – depending on custom post-meta?
- Remove Post Custom Meta Box
- Can’t publish custom post type – “You are not allowed to edit this post.”
- Custom post type posts don’t show in archive widget
- Custom fields for custom post type
- Show future events based on custom field AND order by date
- Showing specific post in order of array wp_query
- Meta Data for Custom Post Type not saving
- Using preg_replace to filter custom textarea
- Check if post with same meta value exists
- Filter date from post meta when date is in string format
- Get only used meta_values
- If Post Meta Equals Current Title Conditional Advanced Custom Fields
- Is there a way to exclude posts based on meta_values?
- Number of posts in the archive
- Query of custom post types only shows first post
- Custom query for custom post_type
- Adding custom field values to wp_list_pages
- Query multiple taxonomies with pre get posts
- How to query 2 custom post types that need to share a slug?
- Do posts, pages and / or custom post type objects have unique ID numbers or can there be multiple objects with the same IDs?
- Archieve.php not loading for custom post type
- Submitting Custom Post Types with custom fields from Front-end form
- create custom meta box with default value
- Query Custom Post Types with checkboxes
- Get $post->ID from a URL
- WP_Query() with custom post type and taxonomy — get all terms?
- Displaying a div from an assigned meta_value when on a page
- Meta data (Tags and Categories) for Custom Posts not showing.
- Display different information of a custom post type
- show all custom posts types in home page
- Create Array from custom post type to display a slider
- Setting Post Title via Meta Data returns Auto-draft
- How to Echo Metadata Value in Currency Format
- Issue on Working with Metabox – Checkbox to enable Sale Items
- Filter posts by tax (dropdown) and meta value
- delete_post_meta() for whole CPT / multiple posts?
- List of child custom post types lists all custom post types
- How to get specific post meta by title or id
- Publish and save specific postmeta to a filtered post_type
- Query custom post type based on post id and custom field value
- Listing custom post types on archive page with array
- How to move a post to different post type with all meta data?
- Make (custom) post type accessible only by custom query
- Why do I have to press the “Update” button twice to save my meta box values?
- Can I query posts by taxonomy conditionally based on post type?
- How can I display a drop-down select of Post Names
- How to conditionally add Custom Post Type to Front Page
- how to show records that don’t have custom meta value
- Graphql: Unable to query (where:{author}) for custom post type
- WP API Response does not show my registered metadata
- How to detect that the save_post hook is calling the callback associated to the current edit post page only
- $post->post_meta not pulling any post in wordpress/php
- Values from meta-box not on $_POST
- WP_Query of custom post type sorted by meta_key has unexpected results
- Query not work for current taxonomy
- Display a post from custom post type only if all the selected taxonomies and custom field value matches the record
- Custom post type suddenly stoped working after WordPress 5 update
- Batch Extract Date from post title and put into ACF custom field
- copy images from custom field to another custom field
- Custom Query: If One Post Object Field Value Is The Same As Another
- Break up posts per page in two sections
- Custom Post Type not showing in main loop
- Custom Post Type setup
- How to show custom field on specific custom post type posts only when filled
- How to handle this specific case of custom post type?
- new WP_query > displays posts only once instead of running through full array
- Pagination on search results page
- Querying a custom post type, but not show duplicates
- Save CTP post meta different values each day without overwriting previous values
- get_post_meta returns NULL in front-end, but correct result in back-end
- Shortcode to return single custom post based on post taxonomy
- Cannot obtain custom meta information
- Problem with adding custom post type meta to header by plugin
- How can I output WPAlchemy repeating fields meta values in my page template?
- Meta box data is saved but NOT displayed in the meta box text field. Why?
- How to call a post’s metadata in shortcode.php?
- Hide text if query has no posts
- How do I get the index for a custom post?
- Getting custom post types to properly display alphabetically
- Create query for both custom post type and category
- Filtering custom posts by custom fields (ACF) [closed]
- Save Metabox Custom Field Value
- Echo custom post meta from options array