Unset field from an array not working as expected
Unset field from an array not working as expected
Unset field from an array not working as expected
This can easily be done with default PHP functions. // Loop through all fields, grab the content and assign it to a new array foreach ( get_post_custom() as $custom ) $new_custom[] = array_shift( $custom ); // Get rid of empty fields $new_custom = array_filter( $new_custom );
If I understand the question you are trying to show both post on single.php something like this should work as a second loop. Put This INSIDE the first loop. Do this so you can get the current post ID $parent_id=the_ID(); // Second Loop $query = new WP_Query( array ( ‘post_type’ => ‘TYPE1’, ‘meta_key’ => $parent_id … Read more
There is no need to change the the_author() function itself. A simple conditional tag will do the trick. Example: <?php /*** on your functions.php file ***/ function ifRegistered() { if(is_user_logged_in()) { the_author(); } else { echo get_the_post_meta($post->ID, ‘your_post_meta_key’, true); // or anything else, of course } } /*** on the template you want to use … Read more
So I’ve managed to solve this. The googl_shortlink function from above now looks like this: function googl_shortlink($url, $post_id = false) { global $post; if (!$post_id && $post) $post_id = $post->ID; elseif ($post_id) $post = get_post($post_id); // list all the active languages in an array $enabled_languages = get_option(‘qtranslate_enabled_languages’); if (is_404()) return; if ($post && $post->post_status != … Read more
Yes, most definitely. Take this skeleton code below as a base for a function that would do what you want, and place it in your functions.php: function your_vimeo_meta_function ($post_id) { // some verifications first if ( $post_id == null || empty($_POST) ) return; if ( !isset( $_POST[‘post_type’] ) || $_POST[‘post_type’]!=’post’ ) return; if ( wp_is_post_revision( … Read more
Two issues with your code in current form: wp_insert_post_data hook runs before the actual insertion happens. In other words post might not not exist yet. Data in this hook does not contain post_id. More fitting hooks to use are those after post insertion is processed: do_action(‘save_post’, $post_ID, $post); do_action(‘wp_insert_post’, $post_ID, $post);
Yes, got the problem. A minute off-track, and it’s wrong! :p On line 80, 87, 93 and 99 in Pastebin Codes, the syntax of media_handle_upload() was wrong. It should be substituted from media_handle_upload($postid,’product_image_1′); to media_handle_upload(‘product_image_1’, $postid); Because the syntax of media_handle_upload() is: media_handle_upload( $file_id, $post_id, $post_data, $overrides ); The $post_id cannot be before $file_id.
The Core “trash post” links in the “Quick Edit” section on edit.php and in the “advanced” form in the “Publish” meta box work over GET not POST. Unless you have altered the form(s) somehow, there is no POST data. All you have is the post ID. To save data when a post is deleted, you … Read more
You should use delete_post_meta( $post->ID, ‘show_links’ ); instead of delete_post_meta( $post->ID, ‘show_links’, 1 ); the last form is used to delete specific values when you have multiple values with the same key. Here you most probably already stored a value which is an empty string that you never deleted and that’s what you get when … Read more