mysql - Wordpress Custom Meta Query without wp functions (wo. wp_query()) -
i have fetch title, description , attachment out of wordpress database without wp_query. can't how fetch both, attachments , meta_descriptions @ same time...
this how query looks far
$query="select post_title, meta_value wp_posts p join wp_postmeta pm on p.id=pm.post_id post_status='publish' , post_type='page' , post_parent=2330 , ( meta_key='_wpseo_edit_description' or meta_key='_wp_attached_file' ) order post_date desc";
this query returns "doubled" results have split within loop
______________________________ | post_title | meta_value | |------------|---------------| | title 1 | 1349 | |------------|---------------| | title 1 | description 1 | |------------|---------------| | title 2 | 1348 | |------------|---------------| | title 2 | description 2 | |____________|_______________|
you wlil need join onto wp_postmeta
table in order of attached information, such file attachments or custom fields.
an example of how this:
select p.*, pm2.meta_value featured_image, pm3.meta_value wpseo_edit_description, pm4.meta_value wp_attached_file `wp_posts` p left join `wp_postmeta` pm2 on p.id = pm2.post_id , pm2.meta_key = 'wp_attached_file' left join `wp_postmeta` pm3 on p.id = pm3.post_id , pm3.meta_key = '_wpseo_edit_description' left join `wp_postmeta` pm4 on p.id = pm4.post_id , pm4.meta_key = '_wp_attached_file' p.post_status = 'publish' , p.post_type = 'page' , p.post_parent = 2330
the normal post fields (post title, description, id, etc) available, along featured_image
, wp_attached_file
, wpseo_edit_description
.
Comments
Post a Comment