You can do it with a posts_where
filter and a subquery. Note that you have to explicitly set suppress_filters
to false, as get_posts
normally ignores filters:
function wpse28018_posts_where( $where ) {
global $wpdb;
$where .= " AND {$wpdb->posts}.ID NOT IN ( SELECT DISTINCT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'alternate_page' )";
return $where;
}
// add the filter
add_filter( 'posts_where' , 'wpse28018_posts_where' );
// do the query
$articles = get_posts(array(
'post_parent' => 0,
'post_type' => 'custom_type',
'suppress_filters' => false
));
// remove the filter so other queries aren't affected.
remove_filter( 'posts_where' , 'wpse28018_posts_where' );
Related Posts:
- Query Posts or Get Posts by custom fields, possible?
- Using get_posts with arguments found in meta keys
- Loop through two different sets of custom fields
- use get_posts to get custom field data, but in one array
- Order posts according to user defined order for meta values?
- get_posts that match a user-specified value on a page
- If meta key exists in get posts function otherwise create it
- Meta Query returns wrong number of posts
- How to find a post using XML-RPC without knowing ID
- get_posts in meta box dropdown not showing latest posts
- get post id using custom filed value
- Loop through incrementing custom fields
- Custom field to array?
- How do I display an article using a WordPress custom field?
- get_post_custom_values not working
- How to add a custom field in the advanced menu properties?
- Sortable Custom Columns in User Panel (users.php)?
- How to rename a custom field?
- Adding Custom Field to Taxonomy Input :Panel
- Unable to get Preview of Uploaded image within a Custom Meta box
- How to filter or search the posts using postmeta tables custom meta fields with wordpress REST API
- Add meta data to the menu
- Custom bulk action for media gallery items
- Copy SEO Meta Desc “Custom Field” to Excerpt field?
- Custom fields won’t display on my blog page
- Order Custom post type loop by custom field (datepicker)
- Localized Date Format for Custom Field
- Check if the value of a field has changed on save_post
- How to edit multiple post with Custom fields
- Saving custom image meta fields
- Complex WP_User_Query call fails on production server
- Query post order by post and desc not working
- If category then echo a custom fields
- How can I show custom fields in the loop only to specific user roles?
- Add conditional custom option to ‘Display name publicly as’ dropdown
- Show 1 post and after a specific date show the next one
- WordPress: custom field display twice
- meta_compare seems to be treating values as strings instead of integers as expected
- Is there any way to get all meta and standard columns for any WordPress object after searching based on meta key and value
- How to add fetchpriority parameter to images in the media library?
- Calling the “wp-link-wrap” pop-up modal
- Shortcode To Display Post Custom Field Value Inside Excerpt
- Editable custom field in WP Admin Dashboard
- How do I add an image upload, custom field to a WooCommerce product?
- Customizing user data
- displaying and sorting comments by a custom field (using PODS plugin) [closed]
- how to display a widget only on a page where the custom field is defined?
- Show values of custom post meta on ‘Add new post’ page?
- Trying to sort and display categories(not posts) by custom field: ‘order’
- Custom tables or custom fields?
- display custom field from inner blog in the main homepage of wordpress multisite
- Post selector as Custom Field
- Show user info in a hovercard [closed]
- Display Custom Meta Box Field Only If Value is Present
- Am I overusing custom fields (for adding nearly 5 images and their titles)?
- WP Query – Is this correct?
- edit_tag_form_fields is depricated but tag_edit_form_fields doesn’t work
- Iterate through users and display users meta info at front-page
- Adding custom field and querying from post table
- How to display a product features dynamically with icons?
- Access ACF fields within custom preview function?
- Scripts and tags will not save or output from my custom meta box
- Using WP Color Picker in Repeatable Fields
- How do I save Multiple fields in a meta box?
- Can I access Posts of custom-fields via URL?
- Output custom field value
- Custom field image to Featured Image
- Best way to achieve multiple links in a post title
- Show array of meta_value in Edit Post Coloum
- plugin-list-category-post custom fields
- custom filed from post in the side bar
- Working with multiple values and metaboxes
- Unable to select image with custom field
- How to automatically change a posts status to draft based on custom field
- How to show ACF fields in Gridbuilder custom block
- Move the metaboxes to the very top of post editor
- WordPress Rest API custom field not updating till i manually update the post
- search based on custom field
- Why isn’t update_post_meta saving?
- Custom fields multiple commas separated values
- Display taxonomy loop using custom field data
- Adding more fields to the registration form
- Add custom field information to source meta data
- use mysql to replace one custom field value with another custom field value
- Change blog post title on main blog page
- Spit out list of distinct instances of custom field?
- Delete custom meta
- Filter and display a specific custom field value [closed]
- one get_posts to return a number of custom posts for each meta value
- Is it possible in WordPress
- Add class from custom field into widget class
- Edit different parts of a page seperately
- Get multiple posts with some custom fields efficient
- I want my post to republish again after adding a custom field
- Custom fields / meta box output
- Creating an If/Else statement using WPAlchemy MetaBox radio boxs
- Get single image from custom fields made with WCK custom fields creator
- Media Custom Fields – get a value with PHP
- How to add google map to custom field
- jaredatch metaboxes on video post formats