Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.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 如何在Wordpress中创建具有分类类别的过滤器_Php_Wordpress_Filter_Taxonomy - Fatal编程技术网

Php 如何在Wordpress中创建具有分类类别的过滤器

Php 如何在Wordpress中创建具有分类类别的过滤器,php,wordpress,filter,taxonomy,Php,Wordpress,Filter,Taxonomy,我需要创建一个带有Wordpress分类类别及其帖子的过滤器,如下图所示 名称、发行人、Isin和Market place下拉列表都是类别。我如何将类别分开,并使用它们的帖子创建一个简单的过滤器?我搜索了更多内容,但不知道如何管理和从何处开始。尝试了该插件,但它并不是我需要的单独类别。 请帮我做这个。 我用这种方法来获取下拉列表 function get_terms_dropdown($taxonomies, $args){

我需要创建一个带有Wordpress分类类别及其帖子的过滤器,如下图所示 名称、发行人、Isin和Market place下拉列表都是类别。我如何将类别分开,并使用它们的帖子创建一个简单的过滤器?我搜索了更多内容,但不知道如何管理和从何处开始。尝试了该插件,但它并不是我需要的单独类别。 请帮我做这个。 我用这种方法来获取下拉列表

function get_terms_dropdown($taxonomies, $args){
                                    $myterms = get_terms($taxonomies, $args);
                                    $output ="<select class='news_cat'>";
                                    foreach($myterms as $term){
                                        $root_url = get_bloginfo('url');
                                        $term_taxonomy=$term->taxonomy;
                                        $term_slug=$term->slug;
                                        $term_name =$term->name;
                                        $link = $root_url.'/?'.$term_taxonomy.'='.$term_slug;
                                        $output .="<option value='".$link."'>".$term_name."</option>";
                                    }
                                    $output .="</select>";
                                return $output;
                                }
                    $taxonomies = array('articles-tax');
                    $args = array('orderby'=>'count','hide_empty'=>false);
                    echo get_terms_dropdown($taxonomies, $args);
 <form role="search" method="get" id="searchform" action="<?php bloginfo('url'); ?>">and dropdowns here</form>
函数获取术语下拉列表($taxonomies,$args){
$myterms=get_terms($taxonomy,$args);
$output=“”;
foreach($myterms作为$term){
$root_url=get_bloginfo('url');
$term_taxonomy=$term->taxonomy;
$term\u slug=$term->slug;
$term\u name=$term->name;
$link=$root\u url.'/?'.$term\u taxonomy.'='.$term\u slug;
$output.=''.$term_name.'';
}
$output.=“”;
返回$output;
}
$taxonomies=array('articles-tax');
$args=array('orderby'=>count','hide\u empty'=>false);
echo获取术语下拉列表($taxonomies,$args);
这样创造了一种形式

function get_terms_dropdown($taxonomies, $args){
                                    $myterms = get_terms($taxonomies, $args);
                                    $output ="<select class='news_cat'>";
                                    foreach($myterms as $term){
                                        $root_url = get_bloginfo('url');
                                        $term_taxonomy=$term->taxonomy;
                                        $term_slug=$term->slug;
                                        $term_name =$term->name;
                                        $link = $root_url.'/?'.$term_taxonomy.'='.$term_slug;
                                        $output .="<option value='".$link."'>".$term_name."</option>";
                                    }
                                    $output .="</select>";
                                return $output;
                                }
                    $taxonomies = array('articles-tax');
                    $args = array('orderby'=>'count','hide_empty'=>false);
                    echo get_terms_dropdown($taxonomies, $args);
 <form role="search" method="get" id="searchform" action="<?php bloginfo('url'); ?>">and dropdowns here</form>

搜索
按钮的URL上传递所有术语
名称
slug
。获取查询字符串并使用函数搜索术语ID:

// Suppose you have term name in URL
// Then find Term ID with Name, or if you have slug in url then change "name" to "slug"
$term = get_term_by( "name", $term_name, $taxonomy );
//$term->term_id;
现在,您必须使用特定的术语ID访问帖子:

$args = array(
    'post_type' => 'YOUR_POST_TYPE',
    'tax_query' => array(
        array(
          'taxonomy' => $taxonomy,
          'field' => 'id',
          'terms' => $term->term_id // You can pass more then one term id like array(32, 65)
        )
    )
);
$query = new WP_Query( $args );

你的意思是说在url@jogesh_pi?上传递所有分类名称?AnahitGhazaryan哦,这是一个打字错误,它的术语名称o例如,我在下拉列表中得到了这些类别,并在它们之后设置了样式我应该做什么@jogesh_pi?@AnahitGhazaryan,对于下拉列表,你必须使用html标记,因此,在选项集
term\u name
中,rest下拉列表的内容相同,但必须更改
等。然后在提交时,您将获得url,如
?\u name=term\u slug&\u issor=term\u slug&\u isn=term\u slug
,然后通过
$\u get
或任何首选方法进行检测,并根据代码进行应用