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

时间:2017-02-15 22:20:24

标签: wordpress custom-post-type advanced-custom-fields taxonomy taxonomy-terms

我已经创建了一个带分类标准的自定义帖子类型。我需要在自定义帖子类型中按元值对分类法帖子进行排序。 我正在使用插件高级自定义字段在我的自定义帖子类型中为我的帖子插入单独的元值字段。到目前为止我还没有 能够根据其价值对帖子分类进行排序。我的问题是,我得到了所有"我的分类标准在前端打印出来。 我想获得与其相关的每个分类法的帖子,而不是所有。我一直在测试通过实现它来获得术语id wp_query数组但没有成功。我只是想单独显示我的分类法并抓住相关的帖子,这是可能的,我做错了什么?

这是我的代码......

    <?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(); 

1 个答案:

答案 0 :(得分:0)

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

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

MyObject * m_instance;
    extern "C"
    {

        void createNew()
        {
          m_instance = new MyObject ("one", "two");
        }

        const char * getCharOne()
        {
            std::cout<< "one" <<m_instance->getFirstString().c_str()<<std::endl;
            return m_instance->m_instance->getFirstString().c_str();
        }
    }
//example.js

var ffi = require('ffi');
var libm = ffi.Library('libExample', {
  'createNew': ["void",[]],
  'getCharOne' : ['string',[]],
});

libm.createNew();
var o = libm.getCharOne();
console.log(o);

请在tax_query()的分类列中编写'taxonomy_slug_name'。

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

相关问题