dongxu1668 2015-06-23 07:57
浏览 14

Wordpress查询+ ACF元查询

I am looking for a code that can contain all queries in one.

The part of the code is :

            <?php $query = new WP_Query(array (  'post_type' => 'post', 'posts_per_page' => '6', 'order' => 'DESC', 'tax_query' => array(
        array(
            'taxonomy' => 'type-article',
            'field' => 'slug',
            'terms' => array( 'interview', 'tribune' )
        ) ) ));

            while ( $query->have_posts() ) :
                $query->the_post();  ?>


                <?php if($post->post_type == "post"){ $version_FR = get_field('versionFRexiste'); $langue = get_field('langue'); }; ?>
                <?php if($langue == "FR" || ($langue == "EN"  && $version_FR == "Non")) :  ?>

                [some code]

                <?php endif; ?>
            <?php endwhile; ?>

inside the WHILE, you find two lines with IF

I would like to include these condition in the query at the TOP where WP_Query.

This code is working but my problem is that I would like to have the same number of results to display (6 here)

Thanks for your help

  • 写回答

2条回答 默认 最新

  • douzhuijing4911 2015-06-23 09:09
    关注

    Please have a look here on the ACF Docs.

    The answer is to write a meta query within the WP-Query, such as:

    $posts = get_posts(array(
    'numberposts'   => -1,
    'post_type'     => 'post',
    'meta_query'    => array(
        'relation'      => 'AND',
        array(
            'key'       => 'color',
            'value'     => array('red', 'orange'),
            'compare'   => 'IN',
        ),
        array(
            'key'       => 'featured',
            'value'     => '1',
            'compare'   => '=',
        ),
    ),
    ));
    
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类