Tuesday, May 31, 2022
HomeWordPress Developmentloop - Examine ACF date subject (if exists) and submit date and...

loop – Examine ACF date subject (if exists) and submit date and order DESC


I’ve an ACF date subject (identical format as submit date) and in my Question I need it to be in comparison with the publish date of the submit:

  • If erstelldatum just isn’t empty use erstelldatum for order
  • If erstelldatum is empty use publish date for order as a substitute
  • Order descending

My code is working to date however the order isn`t proper. It lists all posts with erstelldatum first adopted by these with out. I need them to be ordered descending by the above logic.

Additionally the posts with out the ACF subject are ordered in an odd means… descending all the way down to 2010 adopted by a sudden 2021 and descending from it once more.

Assist is very appreciated!

if ( get_query_var('paged') ) {
    $paged = get_query_var('paged');
} elseif ( get_query_var('web page') ) { // 'web page' is used as a substitute of 'paged' on Static Entrance Web page
    $paged = get_query_var('web page');
} else {
    $paged = 1;
}
  
$custom_query_args = array(
    'post_type'     => array( 'submit' ),
    'order'         => 'DESC',
    'orderby'       => array( 'erstelldatum' => 'DESC', 'date' => 'DESC' ),
    'posts_per_page' => get_option('posts_per_page'),
    'paged' => $paged,
    'meta_query' => array(
        array(
            'relation' => 'OR',
            array(
                'key'     => 'erstelldatum',
                'evaluate' => 'EXISTS',
            ),
            array(
                'key'     => 'erstelldatum',
                'evaluate' => 'NOT EXISTS',
            )
        )

    ),
);
$custom_query = new WP_Query( $custom_query_args );```

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments