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
- is it possible to get a list of URLs from post_content directly in a mysql query via phpadmin?
- Custom API how to return int field
- Problem in MySql query on WordPress [closed]
- SQL Query : how copy all tags of post into their post content in wordpress by sql query
- If meta_key exists then don’t select this post?
- Print data from wordpress sql query
- How to add multiple values with add_query_arg?
- Delete query won’t run
- List of buyers for each product
- Where can I find the SQL to get the most used information by wordpress database?
- query posts only works on the first page
- Custom Query for wp_posts using wp_postmeta
- Query parsing only author ids
- WooCommerce Total # orders [closed]
- What is the best way to cache pages and queries in WordPress?
- 3 queries to update WordPress
- WP Query outputs three items within a div
- SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta
- Can I create my own query in wordpress with traditional methods?
- Modify a query using both a text field and a true/false AFC field
- How do I troubleshoot Maximum execution time of 60 seconds exceeded in updating a Media File?
- Query filter on custom post by current author in post widget for elementor query id
- update $wpdb one query
- Admin Post List table Query filtering “WHERE” for custom post type
- Ascending & descending posts on same page with IF statement
- Prevent executing query for wp_global_styles
- How to use a dynamic term id for the query block
- Querying Posts from ACF Repeater Subfield Select Value
- How to figure out correct wp_options to have autoload=’yes’
- Meta Query compare with LIKE pulls similar post types: 55 and 155, and 1,155
- How to show sticky posts on all pages of the pagination, not just the first page?
- How to get posts that have certain meta key value and order based on another meta key’s value
- Why does $_GET return values but get_query_var does not?
- Sort users in admin screen by meta value whether it exists or not
- Remove posts that start with similar words (like a delete duplicate posts plugin)
- Can I make a Heading block above a query loop block disappear when that query loop has no results?