Populate Select Advanced Field With Data From WP_Query

Support General Populate Select Advanced Field With Data From WP_QueryResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #40933
    PiotrPiotr
    Participant

    Hello,

    I'd like to populate Select Advanced field with data from WP_Query, but not on page load with the default callback function, but dynamically based on value of another field (Radio Button).

    I have already developed AJAX interchange involving jQuery/php so that I am receiving WP_Query data as expected based on Radio Button selected item, then put them into key => value array, but I got stuck on how to actually inject this array into the existing Select Advanced field. Should it be inserted into the [options] key of the field?

    Thanks.

    #40947
    PeterPeter
    Moderator

    Hello,

    If you can create an ajax call to get the query data, please append the value to the option list by using jQuery. The [options] field setting is loaded on page load so if you put your code there, it will not work as expected. Please refer to this topic https://stackoverflow.com/questions/17384705/updating-list-of-select-options-using-jquery-and-ajax

    #40956
    PiotrPiotr
    Participant

    Hi Peter,

    I missed one crucial part: I forgot that the php hook have to actually ECHO the data that is to be used by JavaScript... Now the link you provided makes sense.

    Thank you!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.