Hello
I have placed a layout builder widget, inside this layout builder widget i have some self created recent posts widgets.
– layout builder widget
– recent posts (1)
– recent posts (2)
– recent posts (3)
I need to store the post_id value for every widget in global array. So i can exclude already displayed posts in the next widget. This approach was working fine before a few releases of site origin.
This was the code:
$recentPosts = wp_get_recent_posts([ 'numberposts' => 1, 'offset' => 0, 'category' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => $instance['exclude'], 'meta_key' => '', 'meta_value' =>'', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private', 'suppress_filters' => true ], OBJECT); if(is_numeric($recentPosts[0]->ID)) { array_push($GLOBALS['recentpostWidgetExclude'], $recentPosts[0]->ID); }
In the latest release, this is not working anymore. I have tried to find other solutions with function modify_instance or with hook.
add_filter('siteorigin_widgets_instance_recentpost-widget', 'wbe_filter_button_frontend_instance', 10, 2);
Any ideas.
Greetings
Leza
Hi Leza,
Can you please try and remember when your code stopped working? This will allow me to try and find why this may have stopped working at the time.
Can you please send me the complete code you’re trying to use?
Hello Alex S
Thanks for your answer. I was working on this project before season holidays. Then i stopped working and resumed working at the end of january. Before season holidays the code was working.
That is what i have done.
I added a variable to my functions.php to use as global in widget template file.
Then in my widget template file, i use wp_get_recent_posts with exclude $GLOBALS[‘recentpostWidgetExclude’]. If a post was found, i store the post_id in $GLOBALS[‘recentpostWidgetExclude’] to exclude in next widget.