Wordpress 自定义帖子类型,按元框值对分类术语进行排序

Wordpress 自定义帖子类型,按元框值对分类术语进行排序,wordpress,custom-post-type,advanced-custom-fields,taxonomy,taxonomy-terms,Wordpress,Custom Post Type,Advanced Custom Fields,Taxonomy,Taxonomy Terms,我已经创建了一个带有分类法的自定义帖子类型。我需要在我的自定义文章类型中按元值对分类法文章进行排序。 我使用插件高级自定义字段在我的自定义帖子类型中为我的帖子插入一个单独的元值字段。到目前为止,我已经 我们已经能够获得按其值排序的POST分类法。我的问题是,我在前端打印出“所有”分类法。 我想获得与它相关的每个分类法的帖子,而不是全部。我一直在测试如何通过在 wp_查询数组,但没有成功。我只是想单独展示我的分类法并获取它的相关帖子,这可能吗,我做错了什么 这是我的密码 <?php

我已经创建了一个带有分类法的自定义帖子类型。我需要在我的自定义文章类型中按元值对分类法文章进行排序。 我使用插件高级自定义字段在我的自定义帖子类型中为我的帖子插入一个单独的元值字段。到目前为止,我已经 我们已经能够获得按其值排序的POST分类法。我的问题是,我在前端打印出“所有”分类法。 我想获得与它相关的每个分类法的帖子,而不是全部。我一直在测试如何通过在 wp_查询数组,但没有成功。我只是想单独展示我的分类法并获取它的相关帖子,这可能吗,我做错了什么

这是我的密码

    <?php 
get_header(); 

if( have_posts() ) { 
?>
    <section class="section container">
        <div class="row">
<?php       
            // gets our taxonomy title      
            global $wp_query; 
            $term = $wp_query->get_queried_object();
            $title = $term->name; 
?>
            <!-- show our taxonomy title on the front-end of the site -->
            <header id="<?php echo $term->slug;?>" class="col-md-12">   
                <h1><a href="<?php bloginfo( 'url' ); ?>/?p=493"><span class="glyphicon glyphicon-circle-arrow-left" aria-hidden="true"></span></a><?php echo $title; ?></h1>                            
            </header>`enter code here`
<?php              

        // wp_query-loop for our custom post typ "Personal", sort by meta_value 
        $wp_query = new WP_Query(array(
            'post_type'         => 'Personal',
            'posts_per_page'    => -1,
            'meta_key'          => 'sorterings_nummer',
            'orderby'        => '$term->term_id meta_value',
            'ordertax'       => 'DESC',
            'order'          => 'ASC'
        ));

        // gets our custom post type posts with a thumbnail, title and contact details  
        while( $wp_query->have_posts() ) {
            $wp_query->the_post(); 

            $class = get_field('sorterings_nummer') ? 'class="sorterings_nummer"' : '';

            $titel = get_post_meta(get_the_ID(), 'titel');
            $telefon = get_post_meta(get_the_ID(), 'telefon');
            $mobil = get_post_meta(get_the_ID(), 'mobil');
            $mail = get_post_meta(get_the_ID(), 'mail');
            add_filter('the_content', 'wpautop');
?>
            <article class="col-xs-6 col-sm-4 col-md-4 col-lg-3" >
                <div class="align-center">
                    <div class="content--thumbnail">
                        <?php the_post_thumbnail(); ?>
                    </div>

                    <header class="content--title">
                        <h2><?php the_title(); ?></h2>
                    </header>

                    <section class="content--contactDetails">
                        <h3 class="titel"><?php echo $titel[0] ? $titel[0]: ''; ?></h3>  
                        <p class="telefon"><strong><a href="tel:<?php echo $telefon[0] ?>"><?php echo $telefon[0] ? $telefon[0]: ''; ?></strong></a></p>
                        <p>
                            <a class="mail" href="mailto:<?php echo $mail[0] ?>"><?php echo $mail[0] ? $mail[0]: ''; ?></a>
                            <a class="mobil" href="tel:<?php echo $mobil[0] ?>"><?php echo $mobil[0] ? $mobil[0]: ''; ?></a>
                        </p>
                    </section>    
                </div>
            </article>
<?php 
        } // while content
?>
        </div> <!-- .row -->
    </section> <!-- .container -->
<?php 
} // if 
get_footer(); 

请尝试使用tax_query()检索分配给特定分类术语的帖子

请在下面找到更新的$wp_query()代码:

$wp_query = new WP_Query(array(
            'post_type'         => 'Personal',
            'posts_per_page'    => -1,
            'tax_query'         => array(array('taxonomy' => 'taxonomy_slug_name', 'field' => 'id', 'terms' => $term->term_id )),
            'meta_key'          => 'sorterings_nummer',
            'orderby'           => 'meta_value',
            'ordertax'          => 'DESC',
            'order'             => 'ASC'
        ));
请在tax\u query()的分类列中填写您的“分类法\u slug\u名称”

希望,这可能对您有所帮助。

请尝试使用tax\u query()检索分配给特定分类术语的帖子

请在下面找到更新的$wp_query()代码:

$wp_query = new WP_Query(array(
            'post_type'         => 'Personal',
            'posts_per_page'    => -1,
            'tax_query'         => array(array('taxonomy' => 'taxonomy_slug_name', 'field' => 'id', 'terms' => $term->term_id )),
            'meta_key'          => 'sorterings_nummer',
            'orderby'           => 'meta_value',
            'ordertax'          => 'DESC',
            'order'             => 'ASC'
        ));
请在tax\u query()的分类列中填写您的“分类法\u slug\u名称”


希望,这可能会对您有所帮助。

您能告诉我您希望对文章进行排序的元值中有什么内容吗?请提供一种结构格式,您希望您的分类法及其相关文章能够以这种格式显示和排序。另外,请提供详细信息,您尝试在哪个页面访问分类法文章,就我对你的问题的理解而言,我正在提供答案,如果你有任何疑问,请查看并让我们知道。你能告诉我你想要对文章进行排序的元值中有什么吗?请提供一种结构格式,你想要你的分类法及其相关的文章应该显示和排序。同时提供详细信息,在哪个页面中,您尝试访问分类法帖子,据我了解您的问题,我提供答案,如果您有任何疑问,请查看并让我们知道。非常感谢您!我改了我的鼻涕虫名字,它工作得很好!:)非常感谢你!我改了我的鼻涕虫名字,它工作得很好!:)