Support » Plugin: Simple Fields » getting fields data of a fieldgroup outside the loop

  • I would create a search functionality in header.php that finds posts by simple fields values.

    I need a list of all field names and selectable values that are saved in a fieldgroup.

    i can’t find a function that works outside the loop.
    this function simple_fields_fieldgroup('my_fieldgroup_slug') returns an empty array.

    this is an example image to how search box should be:Image

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Pär Thernström


    You can pass a post id as the second argument to simple_fields_fieldgroup(). See info here:

    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.

    Plugin Author Pär Thernström


    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() )
        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' => '='

    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)

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘getting fields data of a fieldgroup outside the loop’ is closed to new replies.