-
AuthorPosts
-
March 27, 2018 at 5:03 pm #933746
Hi all,
Is there any function.php snippet out there to display Enfold Masonry posts by month or of current month? I want to display masonry posts from specific CPTs by month. So all posts for this month only. All posts for April only and so on.I’m asking because I once used a function posted here for filtering posts before it was part of the default Enfold builder.
Thanks!
March 28, 2018 at 1:37 pm #934274Hey fulanoinc,
Thank you for using Enfold.
How would you know if an item belongs to a specific month? Did you separate the items by “month” category? You can use the “avia_masonry_entries_query” filter for this but I’m not sure if that’s possible.
Best regards,
IsmaelMarch 28, 2018 at 3:03 pm #934335Hi Ismael,
I have not specified a month using categories or tags. All WP posts already have a published date Enfold uses to order CPTs by date. I simply want to use that time stamp of the publish date to filter the posts from this month, next month or just per month. Similar to the way an events plugin might do it.
Thanks,
LeydenMarch 29, 2018 at 1:55 pm #934802Hi,
Thank you for the info. Please try this filter in the functions.php file.
add_filter('avia_masonry_entries_query', 'avia_masonry_entries_query_mod',10, 2); function avia_masonry_entries_query_mod($query, $params) { $posts = get_posts($query); $month = date('m'); $current = array(); foreach( $posts as $post ) { $published = date( 'm', strtotime( $post->post_date ) ); if($month == $published) { $current[] = $post->ID; } } $query['post__in'] = $current; return $query; }
Best regards,
IsmaelMarch 29, 2018 at 4:33 pm #934899Hi Ismael,
Thank you. I added this to the functions.php. Is this adding a filter to the Avia Builder? I can’t see where to implement it after adding to functions.php.
Thanks,
LeydenMarch 30, 2018 at 7:34 am #935137Hi Leyden,
No, this code is filtering the posts for the masonry.
The frontend dropdown filter for masonry is the customization that is out of the scope of our support, you might want to hire a freelancer to do it for you.
If you need further assistance please let us know.
Best regards,
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.