Extending Post Field Class (RWMB_Post_Field)

Support General Extending Post Field Class (RWMB_Post_Field)

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #44588
    Adam HodsonAdam Hodson
    Participant

    I'm attempting to create a new field by extending the RMWB_Post_Field with no luck so far.

    Something like the code below works other than the actual Ajax request to load the posts. When it runs the AJAX request, it doesn't include any actions, so it results in a 400 error.

    
    <?php
    class RWMB_Proper_Link_Field extends RWMB_Post_Field {
    
        public static function add_actions() {
            return parent::add_actions();
        }
    
        static function html( $meta, $field ){
            return parent::html( $meta, $field );
        }
    }
    

    I've tried going through the docs, the parent class, and looking for examples online and just can't seem to figure out what the missing piece is here. Has anyone else run into this issue and knows the right way to approach extending the class?

    #44607
    PeterPeter
    Moderator

    Hello Adam,

    The default select field type of the post field is Select Advanced, and it uses Ajax to get and show the data. So there are two parts: PHP code, which you are extending to use the field structure and Javascript code to trigger the Ajax and send the data to PHP.
    You need to create your own JS code to create Ajax to handle click and return data to the custom Post field. It could be a little bit complicated, please take a look at the file
    /wp-content/plugins/meta-box/js/select-advanced.js
    and documentation https://developer.wordpress.org/plugins/javascript/ajax/

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