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

Can I have multiple database users within WordPress?

1  Asked on January 6, 2022 by shady-m-rasmy

   

How to make float element in tinymce

1  Asked on January 6, 2022 by keizerbridge

   

Site Tagline ended up in permalink

1  Asked on January 6, 2022 by alvsa

   

Remove/hide a specify category-name from the url

2  Asked on January 4, 2022 by andresgl

     

Comments waiting but no comments found

3  Asked on January 4, 2022 by athoxx

   

Ajax load more button for comments wordpress

1  Asked on January 4, 2022 by trello

         

WordPress site not working after move

2  Asked on January 2, 2022 by patrick-bateman

 

How to exclude post body from WP search

1  Asked on January 2, 2022 by nstampler

 

Ask a Question

Get help from others!

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