Hunter WebDev Logo
  • Home
  • Blog
  • Services
    • Website Customization
    • Search Engine Optimization
    • Plugin Development
    • PSD to HTML to WordPress
  • Request a Quote
  • Contact
  • Home
  • Blog
  • Services
    • Website Customization
    • Search Engine Optimization
    • Plugin Development
    • PSD to HTML to WordPress
  • Request a Quote
  • Contact

Blog

Get Post Meta Using a Custom Shortcode

Published On - September 3, 2019

Dan Customize, WordPress
WordPress get post meta shortcode

When working with WordPress you may need to retrieve post meta values in the database that have been added by your theme or a plugin. If you are familiar with PHP this can be done using the native WordPress function get_post_meta(). However in some instances it is easier to simply use a quick shortcode which allows you to grab those values, such as when writing in the WordPress editor. Below is the shortcode that can be added to your child theme functions.php:

The shortcode contains 2 parameters, one for the meta key you are retrieving from and the other is the post ID. If you are just grabbing the meta value for the current page you don’t need to include it as it defaults to the current post ID.

The returned value is also wrapped in a <span> tab with the classes .grab-post-meta-value .id-{id} and .key-{key} (where {id} and {key} are replaced with the shortcode values.

If you aren’t sure what meta keys are saved/available with your post types then you can use a plugin like JSM’s Show Post Meta to reveal meta keys on your posts.

Tags: post meta shortcode WordPress
Previous Post Add Contact Form 7 Mail Tags Quickly
Next Post Disable WordPress Fatal Error Handler

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Latest Posts

  • Disable WordPress Fatal Error Handler

    13 July, 2020

  • WordPress get post meta shortcode

    Get Post Meta Using a Custom Shortcode

    3 September, 2019

  • Firefox Console

    How to Find Your Browsers Console

    29 August, 2019

  • Contact Form 7 Modified Plugin Banner

    Add Contact Form 7 Mail Tags Quickly

    29 August, 2019

  • Easiest Way to Search And Replace a WordPress Site

    3 January, 2019

Contact Us
  • Phone: +1 (833) 420-0650
  • Email: hello@hunterwebdev.io

Follow Us On

Related Articles
Blank Image
Disable WordPress Fatal Error Handler

July 13, 2020

Blank Image
Add Contact Form 7 Mail Tags Quickly

August 29, 2019

Blank Image
Easiest Way to Search And Replace a WordPress Site

January 3, 2019

Hunter WebDev

Featured Services
  • Website Customization
  • Plugin Development
  • PSD to HTML to WordPress
  • Search Engine Optimization
Latest Blog Posts
  • Disable WordPress Fatal Error Handler
  • Get Post Meta Using a Custom Shortcode
  • Add Contact Form 7 Mail Tags Quickly
  • How to Find Your Browsers Console
  • Easiest Way to Search And Replace a WordPress Site
Contact Us

Phone: +1 (833) 420-0650

Email: hello@hunterwebdev.io

© Hunter WebDev 2020