Support

Account

Home Forums Front-end Issues filter post object data based on another post object value ID Reply To: filter post object data based on another post object value ID

  • Hi there. So far this is my idea. I will use a post object for my mall. So what i want to do is reuse the code and try to check if my post object with id field_576bd813ca393
    to use this jscript:

    `jQuery(document).ready(function($) {

    $( ‘#acf-field_576bd813ca393’ ).change(function () {

    var selected_mall = ”; // Selected value

    // Get selected value
    $( ‘#acf-field_576bd813ca393 option:selected’ ).each(function() {
    selected_mall += $( this ).text();

    });

    }).change();
    });`

    and this code on my functions.php:

    
    function acf_admin_enqueue( $hook ) {
    	 
      $type = get_post_type(); // Check current post type
      $types = array( 'post' ); // Allowed post types
     
      if( !in_array( $type, $types ) )
    	  return; // Only applies to post types in array
      
      wp_enqueue_script( 'populate-area', get_stylesheet_directory_uri().'/autopopulate.js' ); // '/assets/js/
     
      wp_localize_script( 'populate-area', 'pa_vars', array(
    		'pa_nonce' => wp_create_nonce( 'pa_nonce' ), // Create nonce which we later will use to verify AJAX request
    	  )
      );
    }
    	 
    		add_action( 'admin_enqueue_scripts', 'acf_admin_enqueue' );

    but my problems are the ff:

    1.) i tried using console.log and document.write to try to log the value of selected_mall but i cant seem to make it display on my console and admin page.

    2.) inside $( ‘#acf-field_576bd813ca393’ ).change(function (), how can i check all the cinemas i had also placed from a previous acf custom field? i know i need to use wp_query right and loop through all data. but if i am to use a post object which has both id and value how can i do it?