If I understand your question correctly, this should work:
function get_event_info($event_id = 0, $info = '' ) {
global $wpdb;
return $wpdb->get_col(
$wpdb->prepare(
"SELECT meta_value from $wpdb->postmeta WHERE
meta_key = '%s' AND post_id IN
(SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = 'event_id' AND meta_value= %s )",
$info, $event_id
)
);
}
Use this like so:
$names = get_event_info( 19 , 'Name' );
if ( ! empty($names) ) {
echo '<ul>';
foreach ($names as $name) {
echo '<li>' . $name . '</li>';
}
echo '</ul>';
}
Please be sure the second parameter is exactly the same as the meta_key
: in your example meta_key = 'Name'
but the SQL query is WHERE meta_key='name'
, case is different!
Related Posts:
- mySQL query. ORDER BY meta_key
- Custom MySQL Query for Post and Post Meta
- simple sql query on wp_postmeta very slow
- How many WordPress SQL Queries per page?
- Search custom post type by meta data
- Multipart/formatted MySQL query problem
- How to display liked posts of current user in wordpress?
- Filter query posts by the count of metas for a meta key
- Are database queries created using WordPress filters protected from SQL injection?
- Save default value for empty or missing post meta
- Mysql / WordPress killing my server with 80k users [closed]
- Slow meta_query with about 4 milion record on wp_postmeta
- Select User by Joining Multiple Meta Value Results
- Remove posts from query for events whose start date has passed
- Update slug (URL) of pending posts via phpMyAdmin
- My SQL function to change user_name
- Query metas (and not : query posts by metas)
- You have an error in your SQL syntax – Help with query
- MySQL variable in query
- how would I create a custom query to get all users, and a related post based on a postmeta field?
- Help with MySQL to $WPDB query
- SQL query to select posts from multiple categories
- How do I see the mysql query generated by get_posts( $args )?
- Alter query with posts_clauses to retrieve NULL values last
- Issue with using add_rewrite_rule() for post querying custom fields
- MySql Query very slow
- Searching With Apostrophe
- WordPress Query wp-terms SLOW
- Query posts according to specific post meta values
- wpdb COALESCE won’t work
- Order by meta value pro first then meta value free in my search function
- Get posts from category with custom query
- how to insert missing tags into the posts through mySQL?
- Ideas how to search & replace post_content when string contains a newline?
- Valid SQL query return empty
- mysql query – how to escape apostrophe?
- Query the WordPress database to get data together with replaced information
- Optimize slow SQL query for multiple meta values
- Updating with $qpdb->query() always returns 0 rows affected
- get_post_meta with WP_query
- Declaring a var, placing it in a query and using the output of the query?
- How to return count of custom post type posts with a specific custom field value via $wpdb?
- WordPress Mysql query and Duplicate
- Help with Related Posts Function
- Combining two meta_values within one row with query
- How to delete all images from code in all post_content
- I want to get on those users their meta value are like “AGENT” .. but this query is not working
- Displaying data from custom table
- Get 2 meta values from meta key column
- PHP Fatal error: Uncaught Error: Call to a member function insert() on null
- SQL query to delete users with multiple meta keys and comments
- Is there any way to get all custom posts and all custom terms with it’s meta in few queries?
- Sort by postmeta on when searching
- OR condition not working
- Trouble migrating custom post types from non-wordpress cms
- Are there any best practices for creating a Like/Favourite feature in WordPress using custom MySQL tables and without any plugins?
- Performance of wp_get_attachment_image_srcset() and wp_get_attachment_image_url()
- How to make MySQL search queries with quotes
- how to get postmeta info based on multiple categories?
- Use $wpdb->get_results with filter based on array
- What is the best way to query posts based on live data?
- Mysql query and odd results
- sql for querying post and their category
- Access Tables with number prefix
- Query multiple meta key values?
- the_date() not working
- Is there a way of increasing the speed of this query?
- When/why does ‘$query->get( ‘tax_query’ );’ return empty?
- How to get link and title of next and previous post on single page
- query multiple taxonomy and show post count
- Categories and products in random order
- Listing posts by grouping dates
- $wpdb->query() vs. $wpdb->get_results() vs. phpMyAdmin
- How to mass delete one line from all posts after site hack
- How to export current year posts from WordPress?
- Advanced SELECT query with condtional statements
- I can’t figure out what’s wrong with this statement. $wpdb->query update
- Different values for get_author_posts_url and get_the_author (posts 2 posts)
- query statement containing variable won’t execute
- Placing a widget with $wpdb query
- Related post based on content
- How to interfere to default search to make it search in custom fields?
- WordPress Insert not working with ajax
- How Do I Delete WordPress Posts Older Than 400 Days, From A WordPress Category
- Merge CPT Taxonomy and Post Taxonomy in $query->set
- How to create a filter and add query params to all links
- WordPress add_query_arg from ajax and make url friendly
- My custom pagination not displaying
- SQL query to bulk change short code in all posts
- Wpdb->last_query returns bad query
- WP search exclude last letter from string
- Show certain number of post from tags
- Wpdb empty result only if language is Russian
- Include custom table in query
- How to fix this insert? Don’t work for me!
- Sort order in get_posts [closed]
- Query unique author ids with published post of type job
- Conditional Tag Custom Querys?
- query posts only works on the first page
- Query filter on custom post by current author in post widget for elementor query id