Is it possible to not display fields not defined as a custom field? I have pages with different custom fields. Would I use the template to control this?
Edit: Not install but how to question.
Is it possible to not display fields not defined as a custom field? I have pages with different custom fields. Would I use the template to control this?
Edit: Not install but how to question.
yes. actually you create a template where you tell the plugin which custom fields you want to display. Install and try. Start editing just a first lines, save and open the edit in any page, then you'll get it.
I have a template defined for several custom fields on a given page. But if I go to another page, which do not have any custom fields or ones that do not match, the template still displays those fields. I would expect that it display only the custom fields are defined on the page and not in the custom field template options.
Am I missing something or is it not functioning correct for me?
oh! I see your problem, very sorry, you need to set an IF ELSE conditionals to do so in your template page, the plugin has nothing to do with it. I'll paste the code I use for those cases:
<?php if ( get_post_meta($post->ID, 'yourkey', true) ) { ?>
<?php echo "[ print your value example: "; echo get_post_meta($post->ID, 'yourkey', $single=true); echo " ]"; ?>
<?php } ?>
Hope it clears your way ;D I am not a php genius but I am learning to work with it step by step. This conditional tells the web to display the custom value for a custom key only if it has something in it. Otherwise it won't print a thing.
Actually the template I'm referring to is Custom Field Template Options in Settings. By default, if you specify a field that doesn't exist on the page, it will still display that custom field on the edit page form. From the looks of the code, if you specify the non-existent fields, it will add them to the page.
Around line 1282 in custom-field-template.php, there is a for loop that iterates over all custom field options. So before it iterates thru all properties of a field in the next for loop, I do a check of whether the field is defined on the page.
if( get_post_meta( $_REQUEST[ 'post' ], $title ) ):
So if the field is defined as a custom field on that page, it will display the custom field option, otherwise do nothing.
The template that displays the page is fine, where I choose what/where custom fields go. I just needed to customize the plugin such that the edit pages did not display non-existent fields.
If the developer see any side-effects to such a mod, please let me know.
Update to show custom field with no value specified
Look up all keys for page:
$custom_keys = get_post_custom_keys($_REQUEST[ 'post' ]);
Instead of get_post_meta(), compare title with key array above:
if( in_array($title, $custom_keys) ):
This topic has been closed to new replies.