WordPress gets a category under all the articles by $wpdb

Source: Internet
Author: User

Create a new PHP file in the root directory of the WordPress program and paste the following code

As the following code comment, modify the $CID This category ID, you can get the article under this category. This query requires a combination of three tables wp_posts, Wp_term_relationships, Wp_term_taxonomy,

According to TERM_TAXONOMY_ID get the article designator, Post_status = ' publish ' refers to the article has been published, post_type= ' post ' refers to the record type is the article, taxonomy = ' category ' refers to the type is the directory.

Then run this file and you will be able to read all the articles in this category.

<?PHPinclude("wp-config.php" ) ; require_once(Abspath. ' Wp-blog-header.php '); Global $wpdb; $CID= 1;//Category ID, only one category is supported      $sql= "Select Id,post_title,post_content from Wp_posts,wp_term_relationships,wp_term_taxonomy WHERE id=object_id and Wp_ term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id and post_type= ' post ' and post_status = ' Publish ' and wp_term_relationships.term_taxonomy_id =$CIDand taxonomy = ' category ' ORDER by ID Desc '; $myrows=$wpdb->get_results ($sql); foreach($myrows  as $b) {      Echo $b->id. " <br/> ";//This is the article ID      Echo $b->post_title. " <br/> ";//This is the article title      Echo $b->post_content. " <br/> ";//This is the content of the article      }?>

WordPress gets a category under all the articles by $wpdb

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.