最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Change query based on post type while staying in loop

programmeradmin1浏览0评论

I have a loop that displays three custom post types.

Thing is, all of these post types use a different logic. 'elemzesek' and 'gyorshirek' use ACF fields which you can see in the meta_query.

However, the 'cikkek' post type, to display the correct articles, would need a

'tag' => get_the_title();

The problem is, if this is added, and it runs for 'elemzesek' and 'gyorshirek' as well, the loops finds no results.

Can someone help me in achieving this?

<?php

    $ceg = get_the_title();
    $ceg_megadasa = get_field('ceg_megadasa');
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $query = new WP_Query( array(
        'post_type' => array('cikkek', 'elemzesek', 'gyorshirek'),
        'posts_per_page' => 10,
        'paged' => $paged,
        'post_status' => 'publish',
        // 'tag' => $ceg,
        'orderby' => 'date',
        'order' => 'DESC',
        'meta_query' => array(
            'relation' => 'OR',
            array(
                'key' => 'ceg_megadasa',
                'value' => get_the_ID()
            ),
            array(
                    'key' => 'ceg_megadasa_gyorshirek',
                    'value' => get_the_ID()
                ),
            
        )
    ) );
?>
发布评论

评论列表(0)

  1. 暂无评论