Support

Account

Home Forums General Issues wp_list_categorie with date picker

Solved

wp_list_categorie with date picker

  • Hello,

    I used date picker to show/hide posts depending on the actual date. User has to enter start date and end date of every post.

    Now I’m trying to use wp_list_categories to get only the categories of posts that are shown today.

    I tried something like:

    $today = date('Ymd');
    $catArgs = array(
       'title_li'          => __( ''),
       'show_option_none'  =>  __( 'nothing today'),
       'taxonomy' => array(
          array(
             'key'   => 'offer_start',
             'compare' => '<=',
             'value'   => $today,
             ),
          array(
             'key'   => 'offer_ends',
             'compare' => '>=',
             'value'   => $today,
             )
          ),
       );
    wp_list_categories( $catArgs ); ?>

    But it’s not really working.

    Thank you for this great plugin and for your time helping me

  • Hi @quasi

    wp_list_categories unfortunately does not support any custom “query” parameters. So if you want to show only the categories of todays posts I think your only option is to loop through all of the active posts. Add their categories to an array and then loop through that array as sort of your own wp_list_categories function.

    Taking it one step further it would probably be a good idea to save this array to a transient that will update each day. https://codex.wordpress.org/Transients_API

    That will avoid any performance issues this would give you if there’s a lot of posts or categories.

  • Hi @jonathan

    Thank you for your fast reply.

    Have a nice day

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘wp_list_categorie with date picker’ is closed to new replies.