ownersbox
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: custom field by defaultI got it now. A slight change to the following function, Thank you.
function custom_add_save($postID){
xtend_updatemetafrompost($postID,’isBuilding’);
}Forum: Developing with WordPress
In reply to: custom field by defaultOk we are very close. It is updating the post_meta table but it is not setting the post id correctly, keeps getting 0.
In the custom add function I have my to update functions with one being commented out, both do the same thing.
function xtend_updatemeta($postID,$metakey,$single_or_list) {
// permits storing or clearing out of meta from form input,
// will work with multi-select inputs
if (is_array($single_or_list)) {
$commalist = implode(‘,’,$single_or_list); // multiple
} else {
$commalist = $single_or_list; // one or blank
}
if (xtend_getmeta($metakey,$postID)) {
update_post_meta($postID, $metakey, $commalist);
} else {
if ($commalist) // dont add if blank
add_post_meta($postID, $metakey, $commalist);
}
}
function xtend_updatemetafrompost($postID,$metakey) {
// call this when you may have form data to stash away
$postvalue = $_POST[$metakey];
xtend_updatemeta($postID,$metakey,$postvalue);
}
function xtend_getmeta($metakey,$postID = ”) {
// call this to grab the data
global $post;
if ($postID == ”) $postID = $post->ID;
return get_post_meta($postID, $metakey, true);
}
function post_testing(){
global $post;
$postID = $post->ID;
_e(“<div id=\”NewOptions\” class=\”postbox\”><h3>”);
_e(‘Options’);
_e(“</h3><div class=\”inside\”>Is Building <input name=\”isBuilding\” type=\”checkbox\” value=\”true\””);
if(xtend_getmeta(‘isBuilding’))
echo(” checked “);
echo(” /></div></div>”);
}function custom_add_save(){
global $post;
$postID = $post->ID;
xtend_updatemetafrompost($postID,’isBuilding’);
//update_custom_meta($postID, $_POST[‘isBuilding’],’isBuilding’);
}
function update_custom_meta($postID, $newvalue, $keyname) {
global $post;
$postID = $post->ID;
add_post_meta($postID, $keyname, $newvalue,true);
}Forum: Developing with WordPress
In reply to: custom field by default@rogertheriault First of all thank you for your help, I’m not sure what I’m doing wrong, the testing function does display on my post page, but I go to save it doesn’t appear to be taking the value.
//On my index.php in the loop
<?php get_post_meta($postID, “isBuilding”, true);?>
////////////////////////////////////////////////////
//In my functions.php
function testing(){
_e(“<div id=\”NewOptions\” class=\”postbox\”><h3>”);
_e(‘Options’);
_e(“</h3><div class=\”inside\”>Is Building <input name=\”isBuilding\” type=\”checkbox\” value=\”true\” /></div></div>”);
}function custom_add_save($postID){
// called after a post or page is saved
if ($_POST[‘isBuilding’]) {
update_custom_meta($postID, $_POST[‘isBuilding’],”isBuilding”); // your checkbox field ie name=my_custom_item
}
}
function update_custom_meta($postID, $newvalue, $keyname) {
// … insert logic …
// TO CREATE NEW META
add_post_meta($postID, $keyname, $newvalue,true);
// — OR– TO UPDATE EXISTING META
update_post_meta($postID, $keyname, $newvalue);
}add_action(‘edit_form_advanced’, ‘testing’);
add_action(‘save_post’, ‘custom_add_save’);Forum: Developing with WordPress
In reply to: custom field by default@rogertheriault That method works great for something I’m work on. Is there a way to use the Custom Field as a counter? If I use your method to setup a counter variable per post that I set to 0, can the user on the front end click a link that can then allow me to increment that value?
Is there a function call that I get set that value? I currently only see gets in the docs.
Thank you