Git Product home page Git Product logo

Comments (8)

Cammoy avatar Cammoy commented on August 26, 2024

I think it sounds correct - maybe its saving the post ids so you can loop through the array of saved post ids using a foreach loop.

from custom-meta-boxes.

ibuilder avatar ibuilder commented on August 26, 2024

Yea looks like it displays the name and value as the post ID. Any way where you can display the name="Post title" and the value="ID" ?

from custom-meta-boxes.

Cammoy avatar Cammoy commented on August 26, 2024

This might help
`
// you can call use post data inside here like

`

from custom-meta-boxes.

mattheu avatar mattheu commented on August 26, 2024

Thanks @Cammoy

That's correct - the post ID is stored in the database. This can then be used to display anything you want in the front end. You can also do get_the_title( $id );

from custom-meta-boxes.

ibuilder avatar ibuilder commented on August 26, 2024

So I'm using gravity forms (http://www.gravityforms.com/) for front end form submission. I'm using a function to populate a select box with gravity's prepopulate action:

add_filter("gform_admin_pre_render", "gform_prepopluate_populate_form");

function gform_prepopluate_populate_form($form){

    //only populating drop down for form id 5
    if($form["id"] != 7)
       return $form;

    //Reading posts for "Business" category;
    //$posts = query_posts(array('post_type' => array('post', 'movies')));
   $posts = query_posts( array( 'post_type' => 'tasks' ) );
   // if ( have_posts() ) : while ( have_posts() ) : the_post();

    //Creating drop down item array.
    $items = array();

    //Adding initial blank value.
    $items[] = array("text" => "", "value" => "");

    //Adding post titles to the items array
    foreach($posts as $post)
        $items[] = array("value" => $post->post_title, "text" => $post->post_title);

    //Adding items to field id 8. Replace 8 with your actual field id. You can get the field id by looking at the input name in the markup.
    foreach($form["fields"] as &$field)
        if($field["id"] == 25){            
            $field["choices"] = $items;
        }

    return $form;
}

Then I used the GF + CPT plugin (http://wordpress.org/plugins/gravity-forms-custom-post-types/) to feed info into my CMB which is a custom posttype like:

array( 
        'id'       => $prefix . 'task', 
        'name'     => 'Task', 
        'type'     => 'post_select', 
        'use_ajax' => false,
        'query' => array( 'post_type' => array('tasks') )
      ),

Doesn't seem to want to take the value from gf.

Moreover if I want to edit the post from the frontend, say using the GF Update Post Plugin (http://wordpress.org/plugins/gravity-forms-update-post/). The GF input doesn't seem to input into CMB.

Hopefully that is clear. Any ideas?

from custom-meta-boxes.

mattheu avatar mattheu commented on August 26, 2024

Let me try and work out what you are trying to do...

  • It looks like you have a form on the front end with a select field that contains a list of 'tasks'.
  • The submitted form creates a post
  • This task is saved as meta on the post
  • When viewing the post in the admin - you want to use CMB to display this field.

A couple of things...

  • When createing the field, CMB uses the field ID as the meta key. To retrieve the data saved by gravity forms, this should be the same as the meta key used by gravity forms.
  • The post select field saves post ids not names/titles. You are setting the gravity form select field 'value' arg to the name. This should be $post->ID instead.

from custom-meta-boxes.

ibuilder avatar ibuilder commented on August 26, 2024

Thanks @mattheu that's excatly what I thought. Now the only problem is when I submit the frontend form to my metabox it doesn't show as the value ID. Since CMB shows the post select as the title ...

// TODO this should be in inside the class
function cmb_ajax_post_select() {

    $query = new WP_Query( $_GET );

    $posts = $query->posts;

    $json = array();

    foreach ( $posts as $post )
        $json[] = array( 'id' => $post->ID, 'text' => get_the_title( $post->ID ) );

    echo json_encode( $json );

    exit;

}

is there an action where I can change:

$json[] = array( 'id' => $post->ID, 'text' => get_the_title( $post->ID ) );

to

$json[] = array( 'id' => $post->ID, 'text' => $post->ID );

so I don't have to modify the base code?

from custom-meta-boxes.

mattheu avatar mattheu commented on August 26, 2024

I'm afraid it is not possible to modify this. If you want to avoid modifying the base code, I suggest you create a new field that extends post_select, and you can have your own custom ajax callback funciton.

from custom-meta-boxes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.