Tagged: , ,

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #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!

    #934274

    Hey 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,
    Ismael

    #934335

    Hi 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,
    Leyden

    #934802

    Hi,

    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,
    Ismael

    #934899

    Hi 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,
    Leyden

    #935137

    Hi 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

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