Show all from specific Month with date field type & perch_content_custom

  • I have events pages that feature a single event that then need to be displayed on a custom calendar on another page. I need to use perch_content_custom() to display all the posts that occur in a specific month but I cannot get the filtering to work properly. Here is my code for the month of august:

    The ID event_date_start is a standard date fieldtype so the data is in the form of Y-m-d H:i:s My thinking is that 'match'=>'contains' would be able to find the month within the date string but it isn't working. I put dashes before the number (-08-) because only the month has a dash before and after it's number. Maybe I need to use 'match'=>'regex' ? I looked for examples of using 'match'=>'regex' and could never get it to work. Kind of at a loss at this point. Any ideas?

  • drewm

    Approved the thread.
  • I'd do exactly what you're currently doing but use regexp instead of contains.


    Contains filters for word boundaries, so your date partial won't match.


    Code
    1. 'filter'=>'event_date_start',
    2. 'match'=>'regexp',
    3. 'value'=> '-08-', //month of august
  • I'd do exactly what you're currently doing but use regexp instead of contains.


    Contains filters for word boundaries, so your date partial won't match.


    Code
    1. 'filter'=>'event_date_start',
    2. 'match'=>'regexp',
    3. 'value'=> '-08-', //month of august

    That worked perfectly.

    Just fyi the perch documentation needs to be updated since it says possible values for match are 'regex' and not 'regexp'

    For example: https://docs.grabaperch.com/fu…ent/perch-content-custom/