Skip to content

Instantly share code, notes, and snippets.

@safwanafridi
Last active January 23, 2024 07:47
Show Gist options
  • Save safwanafridi/5ddf6d7c623cc84f1bcd5c8bfd1cdc83 to your computer and use it in GitHub Desktop.
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
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