WordPress Code Snippets for Retrieving Post Data
Vishal Jaiswal / July 22, 2024 / WordPress
These codes can be used within WordPress themes or plugins to retrieve and display various types of data related to posts and pages.
Name | Code |
---|---|
Title | <?php the_title(); ?> |
Description (Excerpt) | <?php the_excerpt(); ?> |
Full Content | <?php the_content(); ?> |
Featured Image (Thumbnail) | <?php the_post_thumbnail(); ?> |
Author | <?php the_author(); ?> |
Publish Date | <?php the_date(); ?> |
Categories | <?php the_category(); ?> |
Tags | <?php the_tags(); ?> |
Comments Count | <?php comments_number(); ?> |
Custom Field Value | <?php echo get_post_meta($post->ID, ‘your_meta_key’, true); ?> |
Permalink | <?php the_permalink(); ?> |
Post ID | <?php the_ID(); ?> |
Post Format | <?php echo get_post_format(); ?> |
Post Slug | <?php echo $post->post_name; ?> |
Parent Post ID | <?php echo $post->post_parent; ?> |
Comments Template | <?php comments_template(); ?> |
Post Type | <?php echo get_post_type(); ?> |
Post Status | <?php echo get_post_status(); ?> |
Post Date Modified | <?php the_modified_date(); ?> |
Attachment URL | <?php echo wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?> |
URL | <?php echo get_permalink(); ?> |