Wordpress 想从类别slug获得帖子吗
我正在做一个项目,在不同类别的slug中得到相同的结果。请帮帮我,我做错了什么Wordpress 想从类别slug获得帖子吗,wordpress,Wordpress,我正在做一个项目,在不同类别的slug中得到相同的结果。请帮帮我,我做错了什么 $act = $_POST['act']; $args = array( 'posts_per_page' => 100, 'offset' => 0, 'category' => $act, 'orderby' => 'post_date', 'order' => '
$act = $_POST['act'];
$args = array(
'posts_per_page' => 100,
'offset' => 0,
'category' => $act,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'product',
'taxnomy' => 'product_cat',
'post_status' => 'publish');
$myposts = get_posts( $args );
global $product;
global $wpdb;
foreach ($myposts as $key => $value) {
$id = $value->ID;
echo '<li class="product type-product status-publish has-post-thumbnail first grid with-hover add-hover open-on-mobile with-border span3 featured shipping-taxable product-type-simple product-cat-accommodation-durban product-cat-accommodation-battlefields product-cat-battlefields product-cat-comfortable-accommodation-durban product-cat-comfortable-accommodation-battlefields product-cat-durban instock">';
echo '<div class="product-wrapper">';
echo '<a class="thumb" href="'.get_permalink( $id ).'">';
$post_thumbnail_id = get_post_thumbnail_id($id);
$post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
echo '<img src="'.$post_thumbnail_url.'" />';
echo '</a>';
echo '<h3>'.get_the_title( $id ).'</h3>';
echo '</div></li>';
}
$act=$\u POST['act'];
$args=数组(
“每页帖子数”=>100,
“偏移量”=>0,
“类别”=>$act,
'orderby'=>'post_date',
“订单”=>“描述”,
“post_类型”=>“产品”,
“税收”=>“产品类别”,
“发布状态”=>“发布”);
$myposts=get_posts($args);
全球$产品;
全球$wpdb;
foreach($myposts作为$key=>$value){
$id=$value->id;
回声级="产品类型产品状态发布已发布缩略图第一个网格带悬停添加悬停打开移动边界span3特色装运应税产品类型简单产品猫住宿德班产品猫住宿战场产品猫舒适住宿德班产品猫舒适住宿蝙蝠tlefields产品类别德班instock“>”;
回声';
回声';
echo“”。获取标题($id)。“”;
回音“”;
}
经过仔细考虑,我找到了问题的根源:
这里$act的值是多少?@Bhumisah这只是一个类别的slug。我认为你的slug有问题,因为代码看起来很好。这个类别有孩子吗?用过静态slug。但是结果没有变化。嗨,谢谢你的回复。这里我想知道两件事。i)我想用slug过滤,而不是id。ii)公式适用于默认值不适用于woocommerce产品和类别的帖子和类别。
<?php
$slug = "category-b";
$args = array(
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $slug
)
),
'post_type' => 'product',
'orderby' => 'title',
);
$the_query = new WP_Query( $args );
foreach ($the_query->posts as $key => $value) {
print_r($value->ID);
}
?>