Select Choices Callback Function Executed on Front End

Support General Select Choices Callback Function Executed on Front End

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #47258
    Jacob HillJacob Hill
    Participant

    Hello,

    I have a Meta Box custom select field that gets its choices using a PHP callback function that calls an external REST API and then returns the choices for the select field.

    I just realized that the callback is executing on the front end of my website as well which is adding significant loading time due to the responsiveness of the external API.

    When I remove the callback from the choices field, it runs significantly faster (measured using Query Monitor).

    Obviously this callback should only be called on the wp-admin screen where that custom field appears. I'm not sure how to correct this, it seems that this is an issue with the Meta Box plugin?

    Let me know if you need any further information!

    Thank you!

    Jacob Hill

    #47259
    Jacob HillJacob Hill
    Participant

    For now I added logic to my callback function to check if the current page is_admin() and if the page is the edit/new page for the post type that uses the field.

    I feel like Meta Box should include those checks though. 🙂

    Jacob Hill

    #47271
    PeterPeter
    Moderator

    Hello Jacob,

    Do you add the field group that has the custom select field to a frontend submission form? All the field settings should be loaded in the admin area only unless the field is used in the frontend form and the field settings would be loaded in the frontend.

    #47273
    Jacob HillJacob Hill
    Participant

    Hi Peter! The field group is not used in a front-end form (I'm not using that feature right now). The PHP function is included in my plugin's code, but is only called from the field's settings in Meta Box.

    #47290
    PeterPeter
    Moderator

    Hello Jacob,

    Let me check this issue with the development team and I will get back to you when I have more information.

    Thank you.

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