Get Ancestor featured image

Given this hierarchy: Page 1 Page 2 Page 3 Page 4 This line, where $post represents Page 4: $parents = get_post_ancestors( $post->ID ); Will return 3 IDs, for these pages, in this order: Page 3 Page 2 Page 1 So this line: $id = ($parents) ? $parents[count($parents)-1]: $post->ID; Is the equivalent of: $id = ($parents) … Read more

Delete Post From Front-End and attachment permanently

Try: <?php if (current_user_can(‘edit_post’, $post->ID)) echo “<a href=”” . wp_nonce_url(“/wp-admin/post.php?action=delete&amp;post=$id”, “delete-post_’ . $post->ID) . “‘>Delete post</a>” ?> You can decide when to empty the WordPress trash by adding this code to the wp-config.php file in your WordPress root directory. define(‘EMPTY_TRASH_DAYS’, 1 ); The 1 in the code signifies you want to empty the trash everyday. … Read more

Featured Image VS Post_thumbnail — has_post_thumbnail lies?

In your Custom Post Type, do you setup_postdata( $post ) in your custom Loop? If not, has_post_thumbnail() might not be defined/available? EDIT: Try adding: setup_postdata( $post ); Right before: $loop->the_post(); And then see if has_post_thumbnail() returns true? Or, try passing the $post->ID to your call to has_post_thumbnail()? has_post_thumbnail( $post->ID );

How to display thumbnail + tags + title of a child page?

Assuming that you’ve enabled support for both post thumbnails and post tags for static Pages, I would use WP_Query() to build your query, and do something like the following: global $post; $child_pages_query_args = array( ‘post_type’ => ‘page’, ‘post_parent’ => $post->ID, ‘orderby’ => ‘menu_order’ ); $child_pages = new WP_Query( $child_pages_query_args ); if ( $child_pages->have_posts() ) : … Read more

Setting featured image with function, 1 part not working

You have to set the $single paramter of get_post_meta to false (or don’t set it) to get an array. Here is a sped-up version: if ($attachment_id = get_post_meta($post_id, ‘featured_image’, true)) : elseif ($attachment_id = get_post_meta($post_id, ‘upload_single_image’, true)) : elseif ($attachment_id = get_post_meta($post_id, ‘create_gallery’, false)) : $attachment_id = $attachment_id[0][‘upload_image’]; endif; Note: I did not test this. … Read more

Show featured image in sidebar

You can get the Post Thumbnail by get_the_post_thumbnail( ). Inside your widget add the following code: global $post; if ( has_post_thumbnail( $post->ID ) ) echo get_the_post_thumbnail( $post->ID, ‘your-image-size’ ); If there is a Featured Image, it will be shown.