wordpress通过$wpdb获取一个分类下所有的文章
时间:2021-07-01 10:21:17
帮助过:8人阅读
include ( "wp-config.php"
) ;
require_once (ABSPATH.‘wp-blog-header.php‘
);
global $wpdb;
$CID = 1;
//分类id,只支持一个分类
$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 =
$CID and taxonomy = ‘category‘ order by ID desc"
;
$myrows =
$wpdb->get_results(
$sql);
foreach (
$myrows as $b) {
echo $b->ID."<br />";
//这是文章ID
echo $b->post_title."<br />";
//这是文章标题
echo $b->post_content."<br />";
//这是文章内容
}
?>
wordpress通过$wpdb获取一个分类下所有的文章
标签: