Thanks to AmbitiousAmoeba for the answer. The following improved code solves the problem:
function filter_where( $where="" ) {
global $wpdb;
$where .= " AND (($wpdb->postmeta.meta_key = 'original_date' AND $wpdb->postmeta.meta_value >= '2000-01-01') AND ($wpdb->postmeta.meta_key = 'original_date' AND $wpdb->postmeta.meta_value <= '2004-12-31')) ";
return where;
}
add_filter('posts_where', 'filter_where');
query_posts($query_string);
while (have_posts()) :
the_post();
the_content();
endwhile;
Related Posts:
- SQL Query to copy value of a meta_key into another meta_key
- Add custom fields to search
- SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
- How to rename a custom field?
- Bulk move (or copy) from a custom field to the post content?
- Up/Down voting system for WordPress
- Custom Fields Bulk Edit
- Get all posts that do not have a specific custom field without using a subquery
- Order query by meta_value with multiple custom fields
- Custom Field Create Bulk via SQL Query
- UPDATE on SELECT results. A SQL query to swap Author with Meta Box value
- Meta Query And/Or
- Get emails from users by custom field SQL
- SQL: Select wordpress posts with given text string and add a custom field to them?
- Show array of meta_value in Edit Post Coloum
- Change word in woocommerce product category custom field
- SQL query to change the value of a Custom Field
- searching by keywords in post’s metas or pagination links problem
- Convert all dates in field to Unix time, except those already in Unix time
- query specific posts according their custom fields, using sql SELECT
- Alter SQL query to return posts with unique custom field value, no duplicate values
- Update field name without losing the value
- Show Custom Fields in Quick Edit
- Validating Custom Meta Box Values & Required Fields
- Add custom fields to wp native gallery settings
- How can I add extra attribute in the ‘Page Attribute’ section in wp-admin for pages?
- Custom per-page sidebar widgets .. possible?
- Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
- How to add new custom page or post blocks?
- Transients vs CRON +Custom Fields: Caching Data Per Post
- How to update serialized data in the user meta data
- Unable to save datetime custom meta field using update_post_meta() function
- Guest Author – How can I use custom fields to create guest author link?
- enabling custom fields in admin?
- get_post_meta fields don’t show up on posts page
- Using WP Query to search by multiple meta fields
- Get aggregate list of all custom fields for entire blog
- Can ordering post list by meta_value cause performance issue?
- How to Identify the Source of a Custom Field?
- Include woocommerce custom field value in front-end search result
- woocommerce product custom field
- MySQL Query that looks for post with Custom Field, then changes Category
- two custom fields question
- How to save multiple options from a dropdown in user profile
- How to display multiple images in custom field
- How to show a gloabl message on a user profile page (in back end)?
- Display the contents of a custom field of a page on their child
- Read / Watch / Listen times – meta
- Login WP – Connect single field to an external api
- adding extra wordpress user info from registration form
- Custom Meta Box (SELECT) Not Saving
- Ordering posts by custom field named “date” in backend
- How to pass page as an argument like post in WordPress?
- WordPress Media Uploader custom Javascript not working
- Custom fields issue [closed]
- Select custom posts by meta_value and sort by a different meta value
- Front end register with custom fields
- Display custom field from the front page on another page
- Enable a short code in the custom meta field
- Display custom widget value in header.php
- Gravity Forms Update post meta from template [closed]
- Automatic linking terms
- Adding extra fields to front end signup form
- Problem uploading different files as custom fields with front end post form
- How to change order of posts in admin
- Custom product fields in wp e-Commerce plugin [closed]
- make a dropdown custom field with ‘cities’ list in it
- How can I modify my meta_query to work with prices that are stored in the database that contain dollar signs and commas?
- How to add extra field in admin comment section
- wordpress multi user question
- Get Custom Field Name ( Label or Key ) Not Value
- Custom field on Quick Edit using select/dropdown – almost working right but not showing currently selected value
- Type character in name and make it invisble
- How to set up page fields with gutenberg instead of ACF
- Adding Custom Metadata to my Archive/Posts page
- Move the post title to another field
- ACF multi taxonomy on filterable gallery
- Ordering by ACF custom field vaule
- Custom user registration fields in user_register hook
- Unable to change checkout placeholder text
- add different custom fields value to post class if permalink or index
- author.php not showing content if Author has no Posts
- Create Shortcode shows only posts with custom_field meta
- Custom Fields Not Working In Footer
- Login_form add to top of form rather then bottom
- Advanced Custom Fields from Category – IF statement
- Get a different meta value with ajax when different elements are clicked
- Delete custom fields on post publish?
- Permalink structure depending on custom field
- How to add custom_fields value in JSON API using create_post
- CSS conditional on custom field value
- Using Hooks. Thematic
- WP Post Meta Box Field Not Showing Updated Field
- WP_Query based on multiple metadata comparisons
- Parse Shortcodes in Theme’s Custom Field?
- custom field output after the_content
- Post count by meta_key meta_value [closed]
- Change post status by custom fields
- How do delete a meta key?
- Set new url from custom post field