post meta data clearing on autosave
Using save post action I check state: <?php add_action(‘save_post’ ,’my_save_postdata’); function my_save_postdata ( $post_id ) { if ( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE ) { return $post_id; } // logic }
Using save post action I check state: <?php add_action(‘save_post’ ,’my_save_postdata’); function my_save_postdata ( $post_id ) { if ( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE ) { return $post_id; } // logic }
First, content_save_pre is a very old hook. Adam Brown has a warning that: This hook does not occur in the most recent version of WordPress (3.5). Do not use it. It is deprecated. You should look at the list of “related hooks” below to see if you can figure out what replaced it. I would … Read more
The first step is the rewrite rule. I’ve also added a rewrite tag so the custom query var will be parsed. You can also use the query_vars filter for this instead. add_action( ‘init’, ‘tipp_rewrite_rule’ ); function tipp_rewrite_rule() { add_rewrite_tag( ‘%trick_nummer%’, ‘([a-zA-Z0-9]+)’ ); add_rewrite_rule( ‘^tipp([a-zA-Z0-9]+)?’, ‘index.php?trick_nummer=$matches[1]’, ‘top’ ); } The second step is to intercept these … Read more
The problem was a redirect in site-info.php. After that the $_POST variable was empty in the code inserting in the admin_footer. I just need to use a further hook ‘admin_init’ and save the value here. add_action(‘admin_init’, ‘pg_save_custom_site_options’); function pg_save_custom_site_options(){ global $pagenow; if( ‘site-info.php’ == $pagenow && isset($_REQUEST[‘action’]) && ‘update-site’ == $_REQUEST[‘action’] ) { // Use … Read more
You can do this with an action when a new product is inserted (and not when updated). As you did not specify the meta key this field is stored under the user as, OR the meta key of where you want it stored on the product: add_action( ‘wp_insert_post’, ‘smyles_insert_user_product_data’, 10, 3 ); function smyles_insert_user_product_data( $post_ID, … Read more
Prefixing custom fields with an underscore only results in the keys being hidden from the default custom fields UI: There is nothing preventing plugins or theme code from otherwise querying these keys and their values.
get_col() function returns only one column as array. To get two column result we can use get_results(), Which will return an array of objects Which further can be converted into required structure using foreach loop. Example – function get_meta_values( $key = ”, $type=”post”, $status=”publish” ) { global $wpdb; if( empty( $key ) ) return; $r … Read more
Remove the filters and the function used in the tutorial you linked and replace them with this code: add_filter( ‘get_the_author_user_url’, ‘guest_author_url’ ); add_filter( ‘the_author’, ‘guest_author_link’ ); add_filter( ‘get_the_author_display_name’, ‘guest_author_name’ ); function guest_author_url($url) { global $post; $guest_url = get_post_meta( $post->ID, ‘guest-url’, true ); if ( filter_var($guest_url, FILTER_VALIDATE_URL) ) { return $guest_url; } elseif ( get_post_meta( $post->ID, … Read more
Here is an example that adds a custom media field named Buy Now. This example saves the value of the custom field on the media overlay screen via ajax, as well as the media edit screen (non ajax). Edit: Added nonce check and sanitization. /** * Add custom field to media. */ add_filter( ‘attachment_fields_to_edit’, ‘wpse256463_attachment_fields’, … Read more
Less complicated is to use the plugin’s Quicktags and use the Gettext functions to print the content in the site. [:en]English[:pt]Português Quicktags docs Another option is to do just like qTranslate interface does with the post titles: Create one custom field for each language in your meta box: qTrans documentation is not consolidated, so analyzing … Read more