
Tagged: add field to portfolio
-
AuthorPosts
-
March 20, 2025 at 3:52 pm #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 :-)
March 21, 2025 at 4:39 am #1479828Hey 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,
IsmaelMarch 21, 2025 at 8:49 am #1479846Hi 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?March 24, 2025 at 7:50 am #1480022Hi,
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,
IsmaelMarch 25, 2025 at 10:24 am #1480118Hi,
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?
March 26, 2025 at 5:34 am #1480181 -
AuthorPosts
- You must be logged in to reply to this topic.