1

Hey friends: I'm trying to use wordpress custom fields that seem like would be fairly straightforward. I'm using Genesis Outreach Pro child theme

This code is now located in my function.php file:

//* Hook mbr custom shortcode content after header
add_action('genesis_after_header', 'mbr_after_header');

function mbr_after_header() {
  if ( is_singular( 'post' ) )
     $cf = get_post_meta( $post_id, 'mbr_customfield', true );
  if(empty($cf)) {
    echo "Empty Customfield";
  } else {
    echo "".$cf."";
  }
}

My goal is to use the mbr_customfield name to place a unique slider revolution shortcode in the "value" field so that a unique custom slider resolves "after_header" for each page and post.

So I thought maybe the shortcode was the problem. I replaced the slider revolution shortcode with plain text for testing.

You'll see on this page: http://87a.b45.myftpupload.com/backcountry-wedding-destination/ that my hook code at the top right under the header, is echoing "Empty Customfield" but should be echoing whats in the mbr_customfield value which is; Full Width Slider Revolution Shortcode after header will go here

I'd really appreciate if someone can steer me into the right direction. I'd like to be able to use custom fields to accommodate custom sliders "after_header" for each page in this upgrade. It would be really sweet.

After I figure this out, I'll want to replace plain text in the "value" field with shortcode.

2

I'm too new to be able to add a comment, but $post_id looks like it's undefined. You'll need to set it, one way is to grab it from the global $post object like so:

add_action('genesis_after_header', 'mbr_after_header');

function mbr_after_header() {
   global $post;

   if ( is_singular( 'post' ) )
      $cf = get_post_meta( $post->ID, 'mbr_customfield', true );

   if(empty($cf)) {
     echo "Empty Customfield";
   } else {
     echo "".$cf."";
   }
}
  • 2
    you don't need to add a comment. The issue with missing post ID seems real, so this make the yours a valid answer. If you are not sure that your answer will solve all the issues of OP, you can simply state that. In fact, an answer does not have to solve "all" issues, as long it contains useful information and it clearly states that it might not be complete. – gmazzap Sep 5 '16 at 7:31
  • Slightly better solution, is to use get_the_ID() as that pulls in the global, populates it if needs be, and returns the ID all in one go. – GaryJ Sep 19 '16 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.