Error showing in current page id in wordpress admin

While front–end of the site always has a post context (you are either looking at one or archive of posts), admin side doesn’t. So plenty of admin screens won’t have $post global set to anything. You should be checking if it’s meaningful (for example by if ( ! empty( $post ) )) before trying to … Read more

Show button if meta box has content, else hide

Check to see if it’s empty before you show the div. <?php $true_title = get_post_meta( $post->ID, ‘true_title’, true ); ?> <?php if( ! empty( $true_title ) ) : ?> <div class=”discuss”><a href=”https://wordpress.stackexchange.com/questions/166858/<?php echo $true_title; ?>”>Discuss…</a></div> <?php endif; ?>

Meta Box multi checkbox in template

This will be made in the side of the template. First get all the sizes into an array: $allSizes = array( ‘XS’ => ‘Extra Small’, ‘S’ => ‘Small’, ‘M’ => ‘Medium’, ‘L’ => ‘Large’, ‘XL’ => ‘Extra Large’, ‘XXL’ => ‘Extra Extra Large’, ); echo ‘<ul>’; $outStock = get_post_meta($post->ID, ‘Sizes_available’, true); Then let’s compare if … Read more

Metabox not being added

That code doesn’t call the metaboxes of the good screen. Try this to call the metaboxes of the current screen. do_meta_boxes(”, ‘normal’, ‘saed’);

Front end post and upload file, image for users without plugin

Use wp_handle_upload in a custom function if ( $_FILES ) { upload_user_file($_FILES[‘test_upload’]); } if ( ! function_exists( ‘upload_user_file’ ) ) : function upload_user_file( $file = array(), $title = false ) { require_once ABSPATH.’wp-admin/includes/admin.php’; $file_return = wp_handle_upload($file, array(‘test_form’ => false)); if(isset($file_return[‘error’]) || isset($file_return[‘upload_error_handler’])){ return false; }else{ $filename = $file_return[‘file’]; $attachment = array( ‘post_mime_type’ => $file_return[‘type’], ‘post_content’ … Read more

Adding metaboxes to attachment pages

get_post_meta returns an array when you set the 3rd parameter to false, so $value is an array in your metabox callback and you’re treating it as string. I assume an attachment has a single value for license, so you want to set that to true instead.