I believe you can achieve this with WP_Query and avoid the custom SQL:
$today = date( 'Y-m-d' );
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'ID',
'terms' => 15
)
),
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'event_enddate',
'value' => $today,
'compare' => '>='
)
),
'meta_key' => 'event_date',
'meta_value' => $today,
'meta_compare' => '>=',
'orderby' => 'meta_value_num'
);
$events = new WP_Query( $args );
Related Posts:
- How to find if a post with custom_field == X exists?
- What SQL Query to do a simple find and replace
- WordPress Paginate $wpdb->get_results
- Custom Search Query
- Create subpage /user/ or /my-profile/ like /author/ with additional query like /user/user123
- How can I manage my multiple wordpress websites from main website?
- Retrieve and display data from custom db table in admin area?
- Custom search page and search by title, content and tag
- Modifying loop on a custom page, strange behaviour
- How I display post of the post type group by year of post?
- Load more posts with multiple queries
- Hi, I wanted to make custom search with multiple fields
- $wpdb->replace: WHERE?
- wp_query get post custom taxonomy in search.php
- Using $wpdb (WPDB class) ‘replace’ with multiple WHERE criteria problem
- wpdb custom tables without plugin
- Order posts with a custom field but also without
- Save title as custom field on custom post type
- My custom sql query for getting a username giving me a warning and an error
- Add content in between of foreach
- Custom Loop Query For Search Page
- dbDelta not creating tables with composite keys
- Applying WP-cli Search & Replace to Static SQL Dump File
- Query for specific custom field
- Display posts by combining multiple meta key
- Custom select query two tables by a meta key
- Custom Same Page Search
- Fatal error Call to a member function insert() on a non-object [closed]
- custom user meta query
- Recent activity query WordPress
- How to query term_id of a Custom Taxonomy by name
- query_posts meta_key with current date
- saving the widgets position after drag and drop
- WP Search Form Query: Add Author’s posts into search query
- query variables for custom taxonomies
- export and import wordpress customization
- display text generated via custom get query string
- Get All Results From Other Users That Share The Same Custom User Meta As Current User
- What is my error trying to create a new table in the database?
- Custom query pagination with php parameter as arg problem
- How to automatically pull an information from a form field onto an other page?
- Query Posts to display all posts with category “custom field value”
- Add commentmeta custom field to every published comment with SQL
- Query 1 custom post type, each day, alphabetically
- Multiple Taxonomies Using Custom SQL Query
- Search a meta field for a value in all posts
- Custom WordPress SQL Query 4 posts per custom taxonomy
- Custom MySQL query to list post
- Custom Query Arguments
- Custom Query for Taxonomy
- Include plugin´s table in custom query
- User Query Multiple Orderby Clause
- Advanced Custom Fields in WP_Query: Href Returning Empty
- Custom section (e.g. Demos or Downloads)
- change top banner content on specific page
- Is “get_template_part” hierarchy possible?
- Is it possible to rename a customizer control heading?
- Translating (WooCommerce) placeholder text
- WooCommer Product Category Loop – How to change the display order of the rating and price?
- custom query for both category and pages using global $wpdb;
- How to add functionality to an existing theme (using child themes)
- How to add WordPress JS Script Links
- How to add page content into another page
- Display content of metabox if filled in
- Showing Meta Box via Jquery Checkbox
- Localhost wordpress access remote db wordpress website
- add_action does not work when instance multiple tab-containers via template-file
- WordPress Mysql query and Duplicate
- $wpdb is queried but results don’t show
- How to Render Post Types in RSS Feed?
- Custom Form not generating URL
- Custom RSS feed – blank page
- How to display only one category in a custom post type?
- Customizing admin look and feel for just one particular type of user
- How to Add Additional Search Button?
- Using static pages on WordPress site
- Adding Multiple “Parents” in get_categories
- How to move meta information in TwentyTwelve’s single post template?
- Inline-Table under TwentyTwelve not working
- SQL query to get posts from multiple categories but not in a category
- Help with Related Posts Function
- How to remove a settings section from the Theme Customization API preview pane?
- Usage of custom post types in a custom admin menu
- custom css and javascript not working on page defined as template?
- More Fields: Input “Values (if applicable)” is disabled
- How to set up conditionals in page templates?
- Integrating Custom Database with WordPress
- How do I fix my static page
- problem saving/ retrieving custom meta with wp alchemy metabox
- Create Unique ID for user
- Dynamic Sidebars based on page name
- How can I create a basic PHP that can lives outside WP?
- Make a difficult page editable
- URL and Site title outputting on Login page
- get last post’s link with SQL query
- Is it possible to integrate a custom login feature with wordpress?
- User profile Pick a premade Design/theme
- 404 when Previewing an unsaved draft
- How to Remove the Custom Theme Panel from a Theme?
- User Custom Dashboard