Change Beaver Bulider Posts module query in functions.php

I had a site where we had a member dashboard, on which we showed a variety of information, including any posts that the user had published. default Beaver Builder posts module can filter by user but only if you type in the user ID. It doesn’t have an easy way to simply grab the *current* user. So I looked around and found a perfect bit of code which I tweaked to accomplish just this.

Basically the way it works is if you are on the member dashboard page (on this site it’s ID 739) then it runs this code below to tweak the query.

/* -- this changes the query to show posts by current user, but only on the member dashboard page-- */
add_filter( 'fl_builder_loop_query', 'ww_post_module_loop', 10, 2);
function ww_post_module_loop( $query, $settings )
{
if( ! is_page(739) )
return $query; /* << you need this and the line above it so that other queries continue to function as normal */ $query_args = $query->query_vars;
$query_args['post_type'] = array( 'market' ); /* << in our case we are searching for a custom post type */ $current_user = wp_get_current_user(); $query_args['author'] = $current_user->ID; /* << for our case we want to only show posts by current user */ $query = new WP_Query( $query_args ); return $query; }