DsgnWrks

  • Home
  • Code
    • Plugins
      • BibleGateway Links Shortcode
      • CMB2
      • Code Snippets CPT
      • Cubify WP
      • DsgnWrks Importer for Instagram
      • Easy Digital Downloads – Internal Notes for Products
      • DsgnWrks Twitter Importer
      • Enhanced Admin Bar with Codex Search – WordPress Plugin
      • Google Analytics Top Content Widget – WordPress Plugin
      • Hash Link Scroll Offset
      • HTML5 Slideshow Presentation – WordPress Plugin
      • IFTTT Post Formats
      • Jetpack Slideshow Caption
      • Network Sites Counts Dashboard Widget
      • story|ftw
    • All projects
  • Talks
  • Connect
  • About

Leave a Comment

Posted on March 13, 2014

Helper function to check post meta for existence of search string

Today, I needed to find a way to search through the Carrington Build modules for the existence of a shortcode. Personally I needed this so that I could conditionally load some CSS in the head, but you’re reasons may vary. Hope you find it helpful.

/**
 * Check post meta for existence of search string
 */
function check_wp_meta_for_string( $meta_key, $search, $post_id = null ) {

   if ( ! $post_id ) {
      global $post;

      if ( ! isset( $post->ID ) )
         return false;
      
      $post_id = $post->ID;
   }


   // Get serialized meta
   $meta = get_post_meta( $post_id );

   if ( ! isset( $meta[ $meta_key ][0] ) )
      return false;

   return ( false !== strpos( $meta[ $meta_key ][0], $search ) );
}

// Example usage.. Checking if Carrington build modules contains a shortcode
check_wp_meta_for_string( '_cfct_build_data', '[my-shortcode' );

Share the love:

  • Facebook
  • Twitter
  • Reddit
  • Email
  • Tumblr

Like this:

Like Loading...

Category: Snippets, Tools Tags: Carrington Build, custom fields, post meta

← Gary Jones’ Recommended Resources on Avoiding Singletons
Alfred Workflows →

CommentCancel reply

Recent Posts
  • It me!
  • “Is experience exactly the same as pessimism?”
  • WooCommerce: Allow adding multiple products to the cart via the add-to-cart query string
  • Interview on WP Elevation
  • End of an Era: Moving on from WebDevStudios
  • CMB to CMB2 – a migration tale
  • Don’t Repeat Yourself. Use WP Lib Loader instead!
  • What is the future of CMB2?

WordPress Plugin

WordPress Plugin

WordPress Plugin

WordPress Plugin
  • Feeling Generous? Feel free to buy me a coffee! :)
  • Home
  • Code
    • Plugins
      • BibleGateway Links Shortcode
      • CMB2
      • Code Snippets CPT
      • Cubify WP
      • DsgnWrks Importer for Instagram
      • Easy Digital Downloads – Internal Notes for Products
      • DsgnWrks Twitter Importer
      • Enhanced Admin Bar with Codex Search – WordPress Plugin
      • Google Analytics Top Content Widget – WordPress Plugin
      • Hash Link Scroll Offset
      • HTML5 Slideshow Presentation – WordPress Plugin
      • IFTTT Post Formats
      • Jetpack Slideshow Caption
      • Network Sites Counts Dashboard Widget
      • story|ftw
    • All projects
  • Talks
  • Connect
  • About
Twitter
My Tweets
Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Recent Comments
  • Add Multiple Products to WooCommerce Cart using the fetch API - Insytful on WooCommerce: Allow adding multiple products to the cart via the add-to-cart query string
  • JT on DsgnWrks Importer for Instagram
  • andrewpschultz on DsgnWrks Importer for Instagram
  • Rory Heaney on DsgnWrks Importer for Instagram
  • TheBeersBeer on DsgnWrks Importer for Instagram

Copyright © 2025 · All Rights Reserved · DsgnWrks

Swell Theme from Organic Themes · RSS Feed · Log in

  • Github
  • Twitter
  • Linkedin
  • dribbble
%d