5

here's my situation: my client's wordpress site has an "events" custom post type with a custom field called "date" (advanced custom field's datepicker). The site works just fine in all its parts but now they asked me to add a widget-like calendar that fetches all the events.

Basically what i need is something like get_calendar(); but for the "events" post type that uses the "date" custom field instead of the creation date. I spent the whole day yesterday looking for a plugin, hack, snippet of code... but nothing seems to do the job. I know there are similar questions even here on stackoverflow, but still, no solution...

Do you have any ideas?

m_moloch
  • 51
  • 1
  • 2
  • one month later, still fighting with this issue... the closest I came to a solution is [this plugin](https://wordpress.org/plugins/blog-post-calendar-widget/). this shows my custom post type, but I can't understand how to make it use my custom field "date" instead of the publication date... can someone help me out please? – m_moloch Dec 10 '14 at 09:31

1 Answers1

0

OK, so what you need is a widget that has custom query args that will fetch the data you need. You can get the info on widget creation here, and ACF documentation is here. The custom query args should include your custom post type and the ACF data you need. For example:

<?php 
   $args = array (
     'post_type' => 'events', // your custom post type
     'meta_query' => array(
     'relation' => 'AND', // includes ACF stuff
          array(
          'key' => 'date', // the specific key of your ACF
          'compare' => '='
          )
      )
   );
   $query = new WP_Query($args);
?>

This will fetch all the posts from the database from your custom post type that have a date field set. You can modify the value to fit the exact date as well. Or do it through the widget by forwarding a variable for a specific date entered

Skipp
  • 77
  • 4
  • Hey thank you! I'm reading through the widget api documentation, but maybe I'm missing something... when does the "calendar" part comes in? All I need is a little calendar on the homepage, just like the one you get with the get_calendar() function - same behavior, but populated with my events cpt... – m_moloch Oct 30 '14 at 13:59
  • oh, I thought you needed the actual posts. You will need to edit the default widget, or use any other calendar widget and modify the query as stated above so it displays your custom post type data instead of whatever it normally shows. I would just take the display you already have (the calendar visuals) and populate it with the custom query data – Skipp Oct 30 '14 at 14:09