Support

Account

Home Forums Backend Issues (wp-admin) Searching saved options fields

Helping

Searching saved options fields

  • if I use the example code from this ACF doc page https://www.advancedcustomfields.com/resources/query-posts-custom-fields/

    (the penultimate example) how can I adapt it to do a propper WP get_posts search on an options page I have setup that stores its data in a repeater field?

    I have this so far…

    $args = array(
    	'numberposts'	=> -1,
    	'post_type'	=> 'options',
    	'meta_query'	=> array(
    		array(
    			'key'		=> 'repeater_%_subfield',
    			'compare'	=> '=',
    			'value'		=> 'myvalue'
    		)
    	)
    );
    $the_query = get_posts( $args );

    post_type needs changing but options doesn’t seem to work.

  • Options are not save, by default, to any post type and are saved in the options table. It is impossible to search for “options pages” using the default save location. This is because an options value not associated with a “post”. Also, if you have multiple options pages and they all have the same fields/field names, then all of the values for all options pages will have the same value. field names for options pages must be unique.

    If you want to be able to have multiple options pages with the same fields then the first step is probably to set up a custom post type where the values will be stored and use the ‘post_id’ argument to set specific post ID in your custom post type for the save location of the values https://www.advancedcustomfields.com/resources/acf_add_options_page/

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Searching saved options fields’ is closed to new replies.