Tag Info

New answers tagged

0

You are wrong, your custom field is saved but you won't see the value pre-selected in the select box. To see it you have to set the selected attribute of the select element. You can do it easily with selected() function. You should also escape the attribute values and, in your case, use wp_reset_postdata instead of wp_reset_query: ...


2

I am a little confused as to your question. If you know how to create shortcodes with attributes, then I think the answer to your question is to simply output text with the correct attributes predefined. For example, just add text into your custom column for the appropriate arguments, such as echo "[book id=" . $post->ID . "]". The shortcode isn't ...


2

To save: // Update and save the field so it can be used in our template if ( isset( $_POST['input_name'] ) ) { $data = sanitize_text_field( $_POST['input_name'] ); update_post_meta( $post_id, 'field_name', $data ); } To read: $data = get_post_meta( $post_id, 'field_name', true ); // With post object, a leaner, cleaner method: $data = ...


1

Short answer: no. WordPress core has the basic meta box functionality (registering a box & passing a callback) - what that callback does, or how it works, is entirely up to you. You can either code your own implementation, or use a 3rd party as you mentioned.


0

I know this question is old but I find the answers here to not solve the issue. Extending off the answer from Ana Ban, using Otto's method, I found this to be the best method to handle errors. This doesn't require storing the errors in the db. I included a stripped down version of a Metabox object I use. This allows for me to easily add new error messages ...


0

I might as well throw my hat into this ring. This plugin provides an API very similar to the Drupal forms API, and is great for general purposes form generation and processing. https://github.com/oomphinc/WP-Forms-API


2

Resolved by following comment on Tutsplus Tutorial (link included): In function save_meta(), replace this line: if (!wp_verify_nonce($_POST['custom_meta_box_nonce'], basename(__FILE__))) with this line: if (!isset($_POST['custom_meta_box_nonce']) || !wp_verify_nonce($_POST['custom_meta_box_nonce'], basename(__FILE__))) See full comment here.


0

Thanks the the replies. I solved my problem with jQuery. Here is the code: jQuery(document).ready(function ($) { $("#category-tabs li.hide-if-no-js").hide(); //Hides Most Used tab $("#category-all input:checkbox").change(function () { var max = 2; // Max allowed cats var count = $("#category-all input:checked").length; //counts selected cats ...


0

Try the following. Replace ereg('/\edit\.php', $_SERVER['REQUEST_URI']) with preg_match('/edit.php/', $_SERVER['REQUEST_URI']) And also change if(isset($_POST[$meta_box['name'].'_value'])){ $data = $_POST[$meta_box['name'].'_value']; } to if(isset($_POST[$meta_box['name'].'_value'])){ $data = $_POST[$meta_box['name'].'_value']; } else ...


0

It looks like what might be happening is that it is in fact saving it, but you are just not outputting the saved value. For example if you have a text input you will need to get the meta first and then echo it as the value attribute: <?php $my_meta = get_post_meta( $post->ID, 'meta_key', true ); ?> <input type="text" name="name" id="id" ...


0

Try basename( __FILE__ ) instead of plugin_basename( __FILE__ ) I think your nonce is not verifying.


1

Have you noted that you are verifing that the post type is a page and that user can edit pages and posts? if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id ) ) return; } else { if ( !current_user_can( 'edit_post', $post_id ) ) return; } It should be: if ( 'ranch' == $_POST['post_type'] ) { if ...


0

I managed to solve it. The problem was in using a custom post-type with Metabox.php / MediaAccess.php (both from WPAlchemy class) Supposedly you can use custom post-types with WPAlchemy since, when instantiating a WPAlchemy_MetaBox object you can pass some optional parameters to enable that kind of costumization. Like this: $mb = $my_custom_metabox = new ...


0

As @rarst said, setting global $wp_meta_boxes to an empty array can be a solution. Regarding the timing issue, best place to reset the variable is just before it is used. Metaboxes are printed via do_meta_boxes() function and inside it there are no hooks, however it contains get_user_option( "meta-box-order_$page" ) and get_user_option() fires the filter ...


0

If you want to hide all the metaboxes for all users, you can do that through the get_user_option_metaboxhidden_{cpt}, default_hidden_meta_boxes or the hidden_meta_boxes filter, according to the /wp-admin/includes/screen.php file. Here's an example for the post post type: /** * Hide all metaboxes in the global $wp_meta_boxes */ add_filter( ...


0

The source for remove_meta_box() should give you reasonable idea. The registered boxes are stored in $wp_meta_boxes global. Clearing that global (for example by assigning empty array) will prevent them from shoving. The only tricky part would be figuring out the correct context and timing. If you do it too early core or some plugin might add metaboxes ...


0

I swear to god.....!!! Every time I ask a question here I seem to find the answer.... I missed the verification: echo '<input type="hidden" name="meta_box_template_picker_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" />'; Below is the complete code. If you think you can use this please do. If you wish to use it but don't know how: 1. ...


0

Found it out! I needed to put the registered taxonomy to the same post type in the registered_taxonomy() function.


0

add_action('add_meta_boxes', 'add_product_meta'); function add_product_meta() { global $post; if(!empty($post)) { $pageTemplate = get_post_meta($post->ID, '_wp_page_template', true); if($pageTemplate == 'page-templates/product-page.php' ) { add_meta_box( 'product_meta', // $id 'Product ...



Top 50 recent answers are included