Support

Account

Home Forums ACF PRO HELP: tax_query taxonomy NULL

Unread

HELP: tax_query taxonomy NULL

  • This is theme code

    <?php
    $game_boxes = dw_option(‘homepage_postboxes_games’) ?: [];

    if (! $game_boxes) return;
    ?>

    <?php
    foreach ($game_boxes as $gamebox):
    $args = [
    ‘showposts’ => 20,
    ];

    $tax_query = array_map(function($el) {
    if (! empty($el[‘terms_’ . $el[‘taxonomy’]])) {
    return [
    ‘taxonomy’ => $el[‘taxonomy’],
    ‘terms’ => $el[‘terms_’ . $el[‘taxonomy’]]
    ];
    }

    }, array_filter((array) $gamebox[‘tax_query’]));

    if ($tax_query) {
    $args[‘tax_query’] = array_merge([‘relation’ => $gamebox[‘tax_query_relation’] ?? ‘OR’], $tax_query);
    }

    switch ($gamebox[‘orderby’]) {
    case ‘views’:
    $args[‘meta_key’] = ‘views’;
    $args[‘orderby’] = ‘meta_value_num’;
    break;

    case ‘likes’:
    $args[‘meta_key’] = ‘_p_likes’;
    $args[‘orderby’] = ‘meta_value_num’;
    break;

    case ‘date_modified’:
    // $args[‘orderby’] = ‘modified’;
    break;

    case ‘stars’:
    $args[‘meta_key’] = ‘_dw_rating_average’;
    $args[‘orderby’] = ‘meta_value_num’;
    break;

    case ‘google_rate’:
    $args[‘meta_key’] = ‘gp_rating’;
    $args[‘orderby’] = ‘meta_value_num’;
    break;

    case ‘downloads’:
    $args[‘meta_key’] = ‘_downloads_count’;
    $args[‘orderby’] = ‘meta_value_num’;
    break;

    case ‘rand’:
    $args[‘orderby’] = ‘rand’;

    case ‘comment_count’:
    $args[‘orderby’] = ‘comment_count’;

    }

    $args[‘order’] = $gamebox[‘order’] ?? ‘DESC’;
    $posts_list = new WP_Query($args);
    var_dump($args);
    ?>
    <div class=”game-app-box game-box container”>
    <div class=”game-app-box–top grid-row items-center space-between”>
    <h3 class=”box-ttl”><svg class=”icon icon-gamepad”><use xlink:href=”#gamepad”></use></svg> <?php echo $gamebox[‘title’]; ?></h3>
    “>See list
    </div>

    <div class=”posts-list-wrap-scroller”>
    <div class=”posts-list-wrapper grid-row”>
    <?php
    while ($posts_list->have_posts()) {
    $posts_list->the_post();
    echo ‘<div class=”post-item-wrapper”>’;
    get_template_part(‘partials/loop/content-post’);
    echo ‘</div>’;
    }
    wp_reset_postdata();
    ?>
    </div><!– .posts-list-wrapper –>
    </div>
    </div><!– .game-app-box –>

    <?php endforeach; ?>

    This is my setting on admin

    aa

    How wrong on setting admin. Please help, this is first time i use acf pro.

    var_dum($args) =
    array(3) {
    [“showposts”]=>
    int(20)
    [“tax_query”]=>
    array(5) {
    [“relation”]=>
    string(2) “OR”
    [“taxonomy”]=>
    NULL
    [“terms”]=>
    NULL
    [“field”]=>
    NULL
    [“operator”]=>
    NULL
    }
    [“order”]=>
    string(4) “DESC”
    }

Viewing 1 post (of 1 total)

The topic ‘HELP: tax_query taxonomy NULL’ is closed to new replies.