Instead of using the pre_get_posts
hook simply modify your WP_Query
to fetch posts with certain conditions.
$loop = new WP_Query( array(
'post_type' => 'projects',
'orderby' => 'rand',
'posts_per_page' => 1,
'meta_query' => array(
array(
'key' => 'your_field_name',
'value' => 'the_value'
),
),
)
);
This, right from the beginning only fetches the posts that matches the value
for the meta key you provide.
Related Posts:
- Redirect to another page using contact form 7? [closed]
- Accessing post’s meta data based on user’s click of a post
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- How to delete all trashed item in one-go
- Show related posts based of current ACF field name in a single page post (a loop within loop)
- How to create repeater field manually, without plugin (ACF Pro)?
- How Do I Use The WordPress Plugin Posts 2 Posts by Scribu?
- Can we completely remove the WordPress Sitemaps (WordPress 5.5)?
- Adding Custom Fields for Img in Posts
- How To Ignore a Filter On Applying Filter the Content In a Function
- how to display all posts Custom fields dynamically?
- Seriously stuck with some custom meta box/plugin stuff
- Enable comments for post with comments meta box removed
- Custom Post Type causes Page Not Found
- post expire after x days
- add_meta_box Callback not being called
- Plugin allowing for artists, events and venues
- How to get images from EDD post?
- Is there a way to order posts and custom post types as one group?
- how do i remove posts from a WP_Query so the pagination is right?
- Saving Custom Post types and fields to a custom table
- If post has custom field then display css-class
- Replace text in post from cvs
- How do I “get the next 10 posts after post_id == x”?
- get_post_type on post.php
- Assign / update custom field value for all posts (How can I assign only to posts without custom field value?)
- Matching Chapters to a Custom posts [closed]
- auto populate list of questions if user select a category xyz
- Preg Match All doesn’t Allow echo first character for WordPress Taxonomy Tags
- External RSS feed to WordPress Portfolio
- pagination on data fetched using SQL query
- Custom Post Type Fields
- Custom setup of wordpress comments that are displayed
- WordPress custom taxonomy not showing
- Allowing users to Sign-up > Login > Post articles that need approval
- How to Resize the Custom Post Images?
- Amazon.com intergration with WordPress?
- Sticky option for custom post types without using custom fields or plugins
- posts from multiple post types in one slider
- How do we update a custom file upload field with the Advanced Custom Field plugin?
- Modify Posts from Custom_Post_Type within the plugin
- Creating an admin meta box to save post as pending
- Price comparison table based on Custom Post Type?
- How can I store data from custom fields to custom tables?
- 2 wordpress site same database
- Custom Template for wordpress cpt plugin
- “Allowed memory size” problem [closed]
- Get data from wp_posts of mysql in to variables of wordpress-php script
- What hook can I use to modify custom post data before it is displayed on the page?
- “After file loaded” action
- WordPress Stats Plugin: Display Post Views [closed]
- Dictionary-style definition list plugin
- WP Insert Post If user refreshes override new post
- Creating New Dynamic Fields for a Certificate (Number Generation, Code Referencing, and more)
- What snippet do I need to type to show my ACF field show up on my theme?
- Is there a way to make [Table Of Content] plugin while not using revision data?
- need to find duplicated meta value in custom filed and view the posts that have the same value
- Is it possible to pin a post in second position from top
- How to get the custom field value using SQL query
- Register PODS Custom Field with WPGraphQL [closed]
- WordPress is redirecting me to homepage
- get_post_meta shortcode returns empty field
- Is there a hook similar to “save_post” which only fires AFTER the post is completely published?
- Adding custom post category to categories widget
- How to display the custom post related blog by category?
- How to arrange custom posts in the backend/admin by custom taxonomy
- Problem with checked box on wp car manager plugin
- Create multiple posts when a custom post is created
- How can I see $post object in frontend from functions.php?
- Is it possible to customize a wordpress post from outside dashboard(Something like site.com/post-type/post/?e=post_id)?
- Prefix WordPress Taxonomy Tags With Hashtag Symbol Like Twitter
- Failed to load resource: the server responded with a status of 500 () post.php
- How to echo a PHP Code After the Content
- Problem with conditional woocommerce custom checkout field
- How to display all custom fields associated with a post type – IN THE ADMIN AREA?
- How to Save settings of custom tab product page in admin side in a database?
- Displaying friend’s posts only
- Add new post using a page inside the website
- Creating a user ‘add custom field’ section
- Trending Tags based on post views
- Calling an custom field from theme option at the frontend
- WordPress list child pages of custom post type
- What method should I use for a sidebar widget that reads latest posts?
- Synch Custom Post Types (and Custom Fields, Cats, etc.) Between WordPress Sites
- Enforce conditions only for draft posts using WyPiekacz, ignore pending and published posts
- Insert data in custom table during new post creation
- How can i do custom author list?
- WordPress User Frontend Editing Custom Fields
- ACF: Hide a div or template section when a custom field (in a field group) is empty
- PHP $_session is not work in wordpress
- How to hide home title on pages and posts?
- A plugin for software reviews site like this one?
- Links not opening as they should. Custom WP plugin
- Is there a plugin or another way that can help me find out the underlying files of a page/post? [closed]
- Redirect a specific User role not admins automatically to view the post that they just updated
- How to export post tags from wordpress
- public custom posts not showing in my wordpress plugin
- wordpress reusable content blocks
- Passing ajax variable to more than one wordpress plugin function
- Show Custom Post Type taxonomy term that matches custom field