Last active
January 23, 2024 07:47
-
-
Save safwanafridi/5ddf6d7c623cc84f1bcd5c8bfd1cdc83 to your computer and use it in GitHub Desktop.
Code for (Shortcode Creation and Extracting MetaKey Value from Post) | Add this code to function.php file of your WordPress theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function shortcode_listing_expiry() { | |
// Get the current post ID | |
$post_id = get_the_ID(); | |
// Get the _expiry_date meta value for the current post | |
$expiry_date = get_post_meta($post_id, '_expiry_date', true); | |
// Output the meta value | |
if (!empty($expiry_date)) { | |
$output = '<p>Expiry Date: ' . esc_html($expiry_date) . '</p>'; | |
} else { | |
$output = '<p>No expiry date found for this post.</p>'; | |
} | |
return $output; | |
} | |
add_shortcode('show_listing_expiry', 'shortcode_listing_expiry'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment