Modify Meta Box fields after Post has been parsed/initialized

Support General Modify Meta Box fields after Post has been parsed/initialized

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #38892
    Johannes GrossJohannes Gross
    Participant

    It looks like fields are added through the rwmb_meta_boxes filter before the post request as been parsed. So $post is not initialized.

    Is there a way to add or modify fields after $post has been parsed/loaded? E.g. to modify the std, options, value or description?

    Since every code (incl. custom database queries or API calls) in rwmb_meta_boxes runs whether it is needed or not it can slow down the site. If we could conditionally add them based on e.g. the queried post_type, it would speed it up.

    Thank you!

    #38898
    Long NguyenLong Nguyen
    Moderator

    Hi Johannes,

    It is not possible because the post object is initialized at a hook later than init. The filter hook rwmb_meta_boxes run at the init hook with priority 20. If you want to create some conditions before registering the meta box, you can use some WordPress built-in functions like get_option().
    Or use the supported extension MB Include Exclude to load a meta box (field group) based on some condition https://docs.metabox.io/extensions/meta-box-include-exclude/

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