Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm developing a site where better is very quickly becoming the enemy of the good.

I would like to make updating as simple for the client as possible by enabling them to populate boilerplate and images text using a shortcode. However, there is one word within the boilerplate text which needs to be unique for each page and must be added by the client. I was thinking of using a specific custom field key and value, as a way of capturing the unique information.

Is it possible and reasonable to use custom fields for this purpose within the shortcode? I'm having trouble thinking through the syntax. Is there a better way to do this?

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

Not sure I understand your specifics, add details if I am off. I assume:

  1. Your shortcode inside post's content.
  2. You have custom field in that post with value you want.

In this case declare in your shortcode function global $post; and use $post->ID to retrieve custom field.

share|improve this answer
    
You are on the right track. Essentially the shortcode contains the entire content for the page (text, images, etc), with the exception of the variable piece that the end user must enter. Think of something like a diploma, where the variable part is the student's name. I'm just having problems retrieving the custom-field data. Since you suggest it can be done, I just have to work through it. I'm self-taught and I haven't written that chapter yet. ;) –  Ray Mitchell Apr 1 '11 at 16:48
    
@Ray Mitchell had you got to post's ID as I suggested? If you have that then it's easy to retrieve custom field value with get_post_meta()‌​. –  Rarst Apr 1 '11 at 16:55
    
I'm going down that path. This is the first time that I'll be using both shortcodes and custom-fields in a project, so I'm working out the kinks for both of them, then trying to combine. If you can point to some resources (beyond the codex) on using custom-fields I'd appreciate it. –  Ray Mitchell Apr 1 '11 at 17:01
    
Rather than using the custom-field, I'll use attributes in the shortcode. So instead of a simple shortcode - [example], the client will enter the shortcode [example value1="AAA" value2="BBB"]. Thanks for the suggestion –  Ray Mitchell Apr 2 '11 at 0:13
add comment

try the following plugins:

http://wordpress.org/extend/plugins/conditional-custom-fields-shortcode/ or http://wordpress.org/extend/plugins/custom-fields-shortcode/

good luck.

share|improve this answer
    
Thanks for these links. They're also a good option. –  Ray Mitchell Apr 3 '11 at 0:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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