WordPress Development Asked by Kenneth Gervacio on September 3, 2020
global $wpdb;
$custom_post_type = 'post'; // define your custom post type slug here
// A sql query to return all post titles
$results = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_title FROM {$wpdb->posts} WHERE post_type = %s and post_status = 'publish' OR post_status ='draft' ", $custom_post_type ), ARRAY_A );
this will output all my post with publish and draft post
I’m trying to output post that are in the tag (tag1,tag2), adding these code to sql tag_ID = 2 OR tag_ID = 1
"SELECT ID, post_title FROM {$wpdb->posts} WHERE post_type = %s and
post_status = 'publish' and tag_ID = 2 OR tag_ID = 1 OR post_status ='draft' ", $custom_post_type ), ARRAY_A );
But it only return nothing?
1 Asked on January 28, 2021 by danish-mohammed
0 Asked on January 28, 2021 by mads-hansen
0 Asked on January 28, 2021
2 Asked on January 27, 2021 by dc09
0 Asked on January 26, 2021 by hm-dadou
2 Asked on January 26, 2021 by priya
2 Asked on January 25, 2021 by stonesmith
2 Asked on January 24, 2021 by doug-wollison
1 Asked on January 23, 2021 by debiprasad
1 Asked on January 23, 2021 by hoy
0 Asked on January 22, 2021
1 Asked on January 21, 2021 by kostikovmu
4 Asked on January 20, 2021 by wordpressor
0 Asked on January 20, 2021 by lee-bossa
3 Asked on January 20, 2021 by sharp12345
2 Asked on January 20, 2021 by maxnagler
Get help from others!
Recent Questions
Recent Answers
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP