Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1479800

    Dear support,
    would it be possible to add an “Event Date” field to the portfolios? I would then like to display them sorted by this date in the portfolio grid.

    Thanks for any help :-)

    #1479828

    Hey dondela,

    Thank you for the inquiry.

    This is not available by default, but you might be able to apply an ACF Date field to the Portfolio post type and sort the Portfolio Grid based on the field’s value.

    https://www.advancedcustomfields.com/resources/date-picker/

    Add this code in the functions.php file:

    function custom_sort_by_event_date($query, $params) {
        $query['meta_key'] = 'event_date'; 
        $query['orderby'] = 'meta_value';
        $query['meta_type'] = 'DATE';
        $query['order'] = 'ASC';
    
        return $query;
    }
    add_filter('avia_post_grid_query', 'custom_sort_by_event_date', 10, 2);
    

    Make sure that the Date Picker field name is event_date.

    Best regards,
    Ismael

    #1479846

    Hi Ismael,
    thank you this is awesome!

    Would it also be possible to add a “Activated” ACF-checkbox as well?
    How could i adjust this function.php code to just show “avtivated” portfolios sorted by date?

    #1480022

    Hi,

    You could add a meta_query parameter to the filter above.

    function custom_sort_by_event_date($query, $params) {
        $query['meta_key'] = 'event_date'; 
        $query['orderby'] = 'meta_value';
        $query['meta_type'] = 'DATE';
        $query['order'] = 'ASC';
    
        $query['meta_query'] = array(
            array(
                'key'     => 'activate',  
                'value'   => '1',       
                'compare' => '='
            )
        );
    
        return $query;
    }
    add_filter('avia_post_grid_query', 'custom_sort_by_event_date', 10, 2);
    

    https://www.advancedcustomfields.com/resources/checkbox/

    Best regards,
    Ismael

    #1480118

    Hi,
    thank you :-)

    I added a checkbox named “activate” with the values “Ja” and “Nein”. I added you JS as above but the portfolios are not visible anymore. What am i doing wrong?

    #1480181

    Hi,

    In the meta_query above, try to replace the value 1 with “Ja”.

    'value'   => 'Ja', 
    

    Let us know the result.

    Best regards,
    Ismael

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.