Comments (8)
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.
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.
This might help
`
// you can call use post data inside here like
from custom-meta-boxes.
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.
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.
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.
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.
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)
- &get_values() generates warnings HOT 1
- Cannot use both id and page-template in show_on array HOT 1
- Unable to save gmap field when field is within a group
- Improve Gmaps group data fix placement
- Fix Travis build for PHP7.0 HOT 2
- Using Mulitple on post select shows multiple selections on edit HOT 11
- Caminho errado de arquivos HOT 1
- Bug with Grouped WYSIWYG Fields Outputting HTML in Post Edit Screen HOT 8
- WYSIWYG editor not loading the editor but the raw HTML code HOT 2
- Display image loaded in metabox HOT 1
- get 500 error HOT 5
- Textarea field type does not seem to render default value HOT 1
- Warning - Failed opening HOT 1
- Broken include links HOT 1
- Sunsetting HMCMB
- i cant get metaboxees HOT 8
- Fatal Error when saving certain Metabox Groups HOT 1
- Gutenberg compatability
- Issues with SSL HOT 3
- Give the gift of packagist.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from custom-meta-boxes.