Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过posts列表中的税务查询获取分类名称_Php_Ajax_Wordpress - Fatal编程技术网

Php 通过posts列表中的税务查询获取分类名称

Php 通过posts列表中的税务查询获取分类名称,php,ajax,wordpress,Php,Ajax,Wordpress,我有ajax分类过滤,我使用它来获取分类id并按分类列出文章。现在我想在列表视图中显示当前的分类名称 我试图在的上方添加获取猫名((int)$category),但没有显示任何内容。根据我在前端单击的分类法,帖子将被正确列出。如何在帖子列表下打印类别名称 function ajax_filtering() { $category = esc_html($_POST['category']); $args = array( 'post_type' => 'po

我有ajax分类过滤,我使用它来获取分类id并按分类列出文章。现在我想在列表视图中显示当前的分类名称

我试图在
的上方添加
获取猫名((int)$category)
,但没有显示任何内容。根据我在前端单击的分类法,帖子将被正确列出。如何在帖子列表下打印类别名称

function ajax_filtering() {

$category = esc_html($_POST['category']);

$args = array(
              'post_type' => 'post',
              'orderby' => 'name',
              'order' => 'ASC'
             );

if ( isset( $category ) ) :
     
     $args['tax_query'] = 
     array( 
         array( 
               'taxonomy' => esc_html($_POST['taxonomy']),
               'field' => 'id', 
               'terms' => array((int)$category) 
             ) ); 
endif;
 
$the_query = new WP_Query( $args );

?>

<div class="list">

<?php

while ( $the_query->have_posts() ) :
       $the_query->the_post(); 
      

 ?>
        <div class="post">
            <a href="<?php the_permalink(); ?>" class="post-link">
                <?php the_post_thumbnail('post-thumb'); ?>
                    <h4 class="post-name"><?php the_title(); ?></h4>

            </a>
        </div>  
函数ajax\u filtering(){
$category=esc_html($_POST['category']);
$args=数组(
“post_type”=>“post”,
'orderby'=>'name',
“订单”=>“ASC”
);
如果(isset($类别)):
$args['tax_query']=
数组(
数组(
'taxonomy'=>esc_html($\u POST['taxonomy']),
“字段”=>“id”,
'terms'=>数组((int)$category)
) ); 
endif;
$thew_query=newwp_query($args);
?>

您可以使用
get\u term\u by()

$category=get_term_by('id',$category,$\u POST['taxonomy');
回显“.$category->name.”;
有用的链接


echo
查看
$category
的值并查看它打印的内容。尝试以下操作:通过('id',$category,'category')获取术语谢谢!它可以工作:)欢迎…很高兴能提供帮助。
$category = get_term_by('id', $category, $_POST['taxonomy']);
echo '<h4>'.$category->name.'</h4>';