$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>posts - Using a meta_value or postdate to to query and orderby|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

posts - Using a meta_value or postdate to to query and orderby

matteradmin9PV0评论

How do I structure a sql that: 2 checks if meta_value is in future or has no meta_value at all and 1 orders by meta_value (meta_key => datum_event), and conditionally if this meta_value is empty uses postdate to order.

The ordering of the query should be handled like one block (not two ordered sections).

This is a two step issue 1 query 2 orderby. Currently this is my sql (not working): Only if I remove the complete 'meta_query' => array posts with no content for datum_event are shown, the first inner array does work to query posts from the past (compare' => '<=').

$args = array(
    'post_type' => array(
        'nieuws',
        'blog',
        'agenda'
    ),
    'meta_query' => array(
        'relation' => 'OR',
        // if has content for datum_event:
         array(
            'key'     => 'datum_event',
            'value'   => date('Ymd'),
            'compare' => '<=',
             // use datum_event to orderby:
            'meta_key' => 'datum_event',
            'meta_type' => 'DATE',
            'orderby' => 'meta_value',
            'order' => 'ASC',
        ),
        // if has no content for datum_event:
        array(
            'key' => 'datum_event',
            'meta_compare' => 'NOT_EXISTS',
            // order by date:
            'orderby' => 'date',
        ),
    ),
);
Post a comment

comment list (0)

  1. No comments so far