I'm trying to filter post by two things.
Note: The value for "disc_id" is a copy of the post ID from the custom post type it is published from. The post would be created on the front end using gravity forms. So lets assume the form is attached to a page with a post ID of 7020. When the post is published, the meta value for "disc_id" gets the value 7020. What i'd like to do is filter all the post with that particular value.
I've managed to get the first part working, which shows the post of the current user, but not the second part, post based on meta data. Please see the code below and can anyone kindly let me know a possible work around for this? I'll greatly appreciate. Thank you!
function fl_builder_loop_query_args_filter( $query_args ) {
if ( 'dis_board' == $query_args['settings']->id ) {
$query_args['post_type'] = array( 'discussion_board');
$query_args['author'] = get_current_user_id();
}
return $query_args;
}
add_filter( 'fl_builder_loop_query_args', 'fl_builder_loop_query_args_filter' );
I'm trying to filter post by two things.
Note: The value for "disc_id" is a copy of the post ID from the custom post type it is published from. The post would be created on the front end using gravity forms. So lets assume the form is attached to a page with a post ID of 7020. When the post is published, the meta value for "disc_id" gets the value 7020. What i'd like to do is filter all the post with that particular value.
I've managed to get the first part working, which shows the post of the current user, but not the second part, post based on meta data. Please see the code below and can anyone kindly let me know a possible work around for this? I'll greatly appreciate. Thank you!
function fl_builder_loop_query_args_filter( $query_args ) {
if ( 'dis_board' == $query_args['settings']->id ) {
$query_args['post_type'] = array( 'discussion_board');
$query_args['author'] = get_current_user_id();
}
return $query_args;
}
add_filter( 'fl_builder_loop_query_args', 'fl_builder_loop_query_args_filter' );
I assume that the fl_builder_loop_query_args
hook is from Beaver Builder, which means that the $query_args
are args
passed to the WP_Query
. source
In that case you can push some custom field parameters to the $query_args
to get all the posts with matching meta value.
I think it should work something like this,
function fl_builder_loop_query_args_filter( $query_args ) {
if ( 'dis_board' == $query_args['settings']->id ) {
$query_args['post_type'] = array( 'discussion_board');
$query_args['author'] = get_current_user_id();
$query_args['meta_key'] = 'disc_id'; // the assigned meta key
$query_args['meta_value_num'] = 7020; // value we're looking for
}
return $query_args;
}
add_filter( 'fl_builder_loop_query_args', 'fl_builder_loop_query_args_filter' );
Could test this one and see if it works the way you want?