• Resolved Diar

    (@qoroviqidiar)


    I’m trying to get archived posts between two dates: startdate and enddate with meta query. I’m taking the startdate and enddate from url with $_GET[‘startdate’] and $_GET[‘enddate’].
    $firstDayOfMonth = date(“Ym01”, strtotime($_GET[‘startdate’]));
    $lastDayOfMonth = date(“Ymt”, strtotime($_GET[‘enddate’]));
    And here is my query:
    $arguments = [
    ‘posts_per_page’ => 10,
    ‘post_status’ => ‘archive’,
    ‘post_type’ => ‘agenda’,
    ‘meta_query’ => [
    ‘relation’ => ‘AND’,
    [
    ‘key’ => ‘date’,
    ‘compare’ => ‘>=’,
    ‘value’ => $firstDayOfMonth,
    ],
    [
    ‘key’ => ‘date’,
    ‘compare’ => ‘>=’,
    ‘value’ => $lastDayOfMonth,
    ]
    ]
    ];
    When i remove startdate and end date parameters it returns me the archived posts but with startdate and enddate parameters it returns nothing, can anyone please help me with the solution? Thank you very much.

  • The topic ‘Can’t query archived post types’ is closed to new replies.