Use widgets, shortcodes, and/or template tags to easily retrieve and display custom field values for posts or pages.
|Author:||Scott Reilly (profile at wordpress.org)|
|WordPress version required:||3.6|
|WordPress version tested:||5.3|
|Added to WordPress repository:||21-12-2004|
|Total downloads:||114 416|
|Active installs:||4 000+|
Click to start download
Screenshot of the plugin's widget configuration.
Screenshot of the plugin's shortcode builder (not available in the block editor, aka Gutenberg).
I added the template tag to my template and the post has the custom field I’m asking for but I don’t see anything about it on the page; what gives?
echo the return value of the function, e.g.
<?php echo c2c_get_custom('mood', 'My mood: '); ?>
Can I achieve all the functionality allowed by the six template functions using the widget?
c2c_get_custom() (which is only available inside “the loop”), yes, by carefully setting the appropriate settings for the widget.
How do I configure the widget to match up with the template functions?
c2c_get_custom(): not achievable via the widget
c2c_get_current_custom(): set the “Post ID” field to
0, leave “Pick random value?” unchecked, and set other values as desired.
c2c_get_post_custom(): set the “Post ID” field to the ID of the post you want to reference and set other values as desired.
c2c_get_random_custom(): leave “Post ID” blank, check “Pick random value?”, and set other values as desired.
c2c_get_random_post_custom(): set the “Post ID” field to the ID of the post you want to reference, check “Pick random value?”, and set other values as desired.
c2c_get_recent_custom(): leave “Post ID” blank, leave “Pick random value?” unchecked, and set other values as desired.
I don’t plan on using the shortcode builder when writing or editing a post or page, so how do I get rid of it?
If you use the block editor (aka Gutenberg, which is the default editing experience as of WordPress 5.0), then the shortcode builder is not available yet so this situation would be moot for you.
For the classic editor, when on the write or edit admin pages for a page or post, find the “Screen Options” link near the upper right-hand corner of the page. Clicking it slides down a panel of options. In the “Show on screen” section, uncheck the checkbox labeled “Get Custom Field Values – Shortcode”. This must be done separately for posts and for pages if you want the shortcode builder disabled for both sections.
I don’t see the shortcode builder; where is it?
If you use the block editor (aka Gutenberg, which is the default editing experience as of WordPress 5.0), then the shortcode builder is not available yet.
For the classic editor, the shortcode builder/wizard is available in the admin when writing or editing a page or post. On the edit/create page, it’ll be a sidebar widget (in this context, also known as a metabox) labeled “Get User Custom Field Values – Shortcode”. If you don’t see it there (which may be the case since it is hidden by default), find the “Screen Options” link near the upper righthand corner of the page. Clicking it slides down a panel of options. In the “Show on screen” section, check the checkbox labeled “Get Custom Field Values – Shortcode”. This must be done separately for posts and for pages if you want the shortcode builder enabled for both sections.
Can I move the shortcode builder box because it is way down at the bottom of the right sidebar when I create/edit posts?
Yes, any of the boxes on the page when creating/editing posts can be rearranged by dragging and dropping the box name. At the very top of the shortcode builder box the cursor will turn into a four-way array indicating you can click to drag that box. You can move it under the post content box, or higher up on the right side.
Why didn’t the shortcode get inserted into the editor after I clicked the “Send shortcode to editor” button?
Sometimes you have to ensure the text editor has focus. Click within the text editor and make sure the cursor is positioned at the location you want the shortcode to be inserted. Then click the button and the shortcode should get inserted there.
Is this plugin compatible with the new block editor (aka Gutenberg)?
Yes, except that the shortcode builder (a custom tool to facilitate making use of the plugin’s shortcode when creating a post) has not been ported over yet. The template tags, widget, and shortcode itself all function properly.
Does this plugin include unit tests?
- Change: Note compatibility through WP 5.3+
- Change: Unit test: Update unit test install script and bootstrap to use latest WP unit test repo
- Change: Use full URL for readme.txt link to full changelog
- Change: Add link to plugin’s page in Plugin Directory to README.md
- Change: Update copyright date (2020)
- Change: Update shortcode builder widget to 006:
- Fix: Check that
is_block_editor()exists before using it, preventing an error when attempting to edit pages in WP earlier than 5.0
- Fix: Check that
- New: Add changelog for v3.9 to CHANGELOG.md
- Fix: Default ‘this_post’ shortcode attribute to 1 instead of 0, since unlike widgets, shortcodes generally appear within the context of a post
- Fix: Call
wpdb::prepare()with the proper number of arguments depending on context
- Change: Update shortcode builder widget to 005:
- Don’t show shortcode builder metabox within context of block editor
- Change: Update widget to 012:
- Directly load textdomain instead of hooking it to already-fired action
- New: Add README.md
- New: Add CHANGELOG.md and move all but most recent changelog entries into it
- Change: Update docs to reflect that shortcode builder is not compatible with block editor yet
- Change: Use different markdown formatting for shortcode name to avoid capitalization when displayed in Plugin Directory
- Change: Add GitHub link to readme
- Change: Unit tests: Minor whitespace tweaks to bootstrap
- Change: Note compatibility through WP 5.1+
- Change: Update copyright date (2019)
- Change: Update License URI to be HTTPS
- New: Add support for percent-substitution tags
- Tags can be used in before and/or after text and will be replaced on display with the custom field text
- Add ‘%field%’ to display custom field name
- Add ‘%value%’ to display custom field value
c2c__gcfv_do_substitutions()to handle the substitutions
- Fix: Properly handle serialized meta values
- Fix: Properly sanitize field name prior so use as part of a hook name
- Fix: Add missing textdomain for string in shortcode widget
- Change: Update widget to 011:
register_widget()and change to calling it when hooking ‘admin_init’
- Load textdomain
- Add more substantial unit tests
- Change: Update widget framework:
get_config()as a getter for config array
- Go back to non-plugin-specific class name of c2c_Widget_012
- Don’t load textdomain
- Declare class and
widget_body()as being abstract
- Change class variable
$configfrom public to protected
- Discontinue use of
- Apply ‘widget_title’ filter to widget title
- Add more inline documentation
- Minor code reformatting (spacing, bracing, Yoda-ify conditions)
- Change: Update shortcode builder widget to 004:
get_config()to get widget config now that the object variable is protected
register()and change to calling it when hooking ‘init’
- Add more unit tests
- Change: Update unit test bootstrap
/tmp/wordpress-tests-librather than erroring out if not defined via environment variable
- Enable more error output for unit tests
- Change: Use officially documented order of arguments for
- Change: Rephrase conditions to omit unnecessary use of
- Change: Tweak readme.txt (minor content changes, spacing)
- Change: Note compatibility through WP 4.7+
- Change: Update copyright date (2017)
- New: Add LICENSE file
- Change: Update widget framework to 011:
- Change class name to c2c_GetCustomFieldValues_Widget_011 to be plugin-specific.
- Set textdomain using a string instead of a variable.
load_textdomain()and textdomain class variable.
- Formatting improvements to inline docs.
- Change: Add support for language packs:
- Set textdomain using a string instead of a variable.
- Don’t load textdomain from file.
- Remove .pot file and /lang subdirectory.
- Remove ‘Domain Path’ from plugin header.
- Add ‘Text Domain’ to plugin header.
- Change: Reformat plugin settings code (spacing).
- Change: Explicitly declare methods in unit tests as public.
- Change: Minor improvements to inline docs and test docs.
- New: Create empty index.php to prevent files from being listed if web server has enabled directory listings.
- Change: Note compatibility through WP 4.4+.
- Change: Update copyright date (2016).
Full changelog is available in CHANGELOG.md.