Support

Account

Home Forums Bug Reports Query Posts by sub custom Field values Reply To: Query Posts by sub custom Field values

  • Hi again John.

    Could not get your code to work, the code you so kindly share here: https://acfextras.com/dont-query-repeaters/

    So I modified it and had to use the field keys like so:

    add_action('acf/save_post', function( $post_id ) {
    
    	$meta_key = '_book_authors';
    	$saved_values = array();
    	$authors = $_POST['acf'];
    
    	if( $authors ) {
    		foreach( $authors['field_55bf6c9024b5f'] as $key => $author ) { // field_55bf6c9024b5f: ACF field key for "book_authors" meta field
    
    			$author_id = $author['field_55dafbfa91614'];  // field_55bf6c9024b5f: ACF field key for "book_authors" meta field
    			add_post_meta( $post_id, $meta_key, $author_id, false );
    
    		}
    	}
    	
    }, 20, 1 );