Forum Replies Created

Viewing 7 replies - 1 through 7 (of 7 total)
  • Forum: Plugins
    In reply to: [CMB2] Export / Import
    Thread Starter ramblurr

    (@ramblurr)

    I’m asking because I’m creating an interface with CMB2 for users to manage a bunch of data in their WP backend.

    Part of launching the new interface is migrating the data from the existing source, CSV.

    Can you point me to the API functions I can use to write data into the fields I’ve created with CMB2?

    Thread Starter ramblurr

    (@ramblurr)

    Alright, I’ve hacked it up myself.

    I changed the
    In CMB2_Field.php, I changed the replace_hash function to be:

    public function replace_hash($value)
    {
        if (!$this->options('group_title_callback')) {
    
            // Replace hash with 1 based count
    
            return str_ireplace('{#}', ($this->count() + 1) , $value);
        }
        else {
            $fields = array();
            foreach(array_values($this->args('fields')) as $field_args) {
                $field = new CMB2_Field(array(
                    'field_args' => $field_args,
                    'group_field' => $this,
                ));
                $fields[$field_args['id']] = $field->value;
            }
    
            return call_user_func($this->options('group_title_callback') , $fields);
        }
    }

    Then in my metabox setup, I set:

    'group_title' => 'New Widget',
    'group_title_callback' => array($this, 'format_group_title'),

    and finally my formatting callback that sets the title based off the field values:

    public function format_group_title($fields) {
            return $fields['time'] . ' ' . $fields['name'];
    }

    This results in new items having the title “New Widget”, and existing groups getting an informative title based off two fields.

    It’s a bit of a hack, is there a way to do this without editing CMB2? I’d rather not break automatic updates and maintain my own fork.

    Edit: improved slightly

    Doesn’t work for me. Given all the unanswered support requests and lack of updates, I’m guessing it is no longer maintained.

    Thread Starter ramblurr

    (@ramblurr)

    Also searching in any fields other than post content doesn’t work.

    The new %caption% placeholder is great, however it currently uses the “caption” configured in the Media library itself. Which is fine in some cases, however sometimes you want to you use the [caption ... caption='something different'] shortcode to specify a different caption in a post/page.

    Any chance it could support both media library captions and inline captions?

    It would be super if you could add Wikipeida and Wikimedia Commons as a data source!

    See: https://en.wikipedia.org/wiki/Quechua_people#mediaviewer/File:Quechuawomanandchild.jpg

    Thread Starter ramblurr

    (@ramblurr)

    More errors:

    Notice: Undefined index: dotall in /.../wp-content/plugins/search-regex/search-regex.php on line 55
    
    Notice: Undefined index: case in /.../wp-content/plugins/search-regex/search-regex.php on line 55
    
    Notice: Undefined index: multi in /.../wp-content/plugins/search-regex/search-regex.php on line 55
    
    Notice: Undefined variable: sql in /.../wp-content/plugins/search-regex/searches/post_content.php on line 13
Viewing 7 replies - 1 through 7 (of 7 total)