2
votes

I need to customize SQL query in wpDataTables to create a table from custom post type 'stock' that have acf fields, so I have two tables: 5s_posts and 5s_postmeta. This code shows up row with meta key trade_in and it's meta value. But I need to retrieve all meta key and it's values table 5s_postmeta that coresponds to post ID from 5s_posts.

SELECT meta_value AS 'trade_in'FROM 5s_postmeta WHERE meta_key = 'trade_in' AND post_id IN(SELECT ID FROM 5s_posts WHERE post_type = 'stock' AND post_status = 'publish') 

5s_postmeta table exemple: 5s_postmeta table exemple

5s_posts table exemple:

5s_posts table exemple

1

1 Answers

0
votes

You can use WordPress get_post_meta() for retrive meta value by key and also all meta values

Get all meta values with all keys. this below code will return an array with all meta of passed post id.

<?php $all_meta = get_post_meta( $post_id ); ?>