You can pass a post id as the second argument to simple_fields_fieldgroup(). See info here: http://simple-fields.com/documentation/api/getting-values/simple_fields_fieldgroup/
Is there not a specific post ID to pass, i need to find all posts matching the search query sent by the user.
To create the search query i need to build a form with inputs named as simple fields names and with related values.
ah, ok. perhaps the method get_field_group() does what you want.
// Get and display info about a field group
global $sf;
$my_field_group_id = 10;
$field_group_info = $sf->get_field_group( $my_field_group_id );
sf_d( $field_group_info , '$field_group_info' );
all the info should be in the variable $field_group_info.
thank you a lot! it’s all what i needed!
If you could show me an example of query where i can find posts with simple fields … it will be great!
this works?
query_posts(array('numberposts' => '10', 'post_type' => array('filmp', 'corp', 'post'), 'meta_key' => '_simple_fields_fieldGroupID_1_fieldID_3_numInSet_0', 'meta_value' => 'dropdown_num_3'));
I’m having some trouble with the query
My post are intended to be of custom type only, so i used pre_get_posts hook to modify the main loop, then i use the query->set to filter posts
add_action( 'pre_get_posts', 'filtri_di_ricerca');
function filtri_di_ricerca( $query ) {
if ( is_admin() || ! $query->is_main_query() )
return;
if (is_home())
{
$query->set('post_type', 'post_annunci');
$meta_query = array('relation' => 'AND');
// Only check these form fields
$fields = array( 'annuncio_contratto', 'annuncio_categoria', 'annuncio_tipologia', 'annuncio_citta');
foreach( $fields as $field )
{
if( $_GET[$field] != '' )
{
// We have something to match, otherwise ignore the field...
$meta_query[] = array(
'key' => $field,
'value' => $_GET[$field],
'compare' => '='
);
}
}
$query->set('meta_query',$meta_query);
}
I have some problem obtaining the meta keys as _simple_fields_fieldGroupID_1_fieldID_3_numInSet_0 instead of $fields, because in the search form i use input fields slugs as input names, so my $_GET variabiles are like annuncio_contratto=dropdown_num_16
I seen an example in your blog post where you can order by the field slug, is there a similar way to launch a query with a field_slug?
Or get the meta_key giving the slug?
I cannot figure out to use action_pre_get_posts_meta($query)