I'm going nuts over this... I need to make bbPress group search to find only those groups where a specific string is inside a meta field.
I tried what I found here: https://codex.buddypress.org/plugindev/group-meta-queries-usage-example/
I use a different meta field, but tried to implement this as it should be. I can update and read the meta value, but I cannot make the meta_query thing work.
I can see the filter_ajax_querystring function is being executed, because I placed a couple of echo's there to test, and the search term is also there, it only doesn't find the group with the meta key - and it is there.
Anyone who can shed some light? What am I missing?
This is my groups-loop:
$params['meta_query'] = array(
array(
'key' => 'bp_symbol_code',
'value' => $_REQUEST['s'],
'compare' => '='
)
);
if ( bp_has_groups( bp_ajax_querystring( 'groups' ) . '&' . http_build_query( $params ) ) ) {
while ( bp_groups() ) {
bp_the_group();
// redirect after header definitions - cannot use wp_redirect( $location );
?>
<script type="text/javascript">
<!--
window.location= '<?php echo bp_group_permalink(); ?>';
//-->
</script>
<?php
}
}
Ok, I feel stupid....
This was the problem:
if ( bp_has_groups( bp_ajax_querystring( 'groups' ) . '&' . http_build_query( $params ) ) )
bp_has_groups() was receiving both an array and a query string...
So the solution was just to change the above with this:
if ( bp_has_groups( array_merge( bp_ajax_querystring( 'groups' ), $params ) ) )
Thanks Gavin, your comments eventually made me realise that mistake :)