AnswerBun.com

how to list all post that are in the custom taxonomy using $wpdb

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?

Add your own answers!

Related Questions

Sending current featured image to email

0  Asked on January 26, 2021 by hm-dadou

   

wp_mail doen’t send mails whit attachment

2  Asked on January 25, 2021 by stonesmith

   

How to get category id of current post?

5  Asked on January 24, 2021 by jrcollins

 

preg_replace regex problem

1  Asked on January 23, 2021 by jim-worrall

   

How to display a sidebar only for blog?

1  Asked on January 23, 2021 by johny-j

 

Fill post titles from post content?

1  Asked on January 23, 2021 by cecily

     

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP