{"id":6251,"date":"2009-07-30T11:27:44","date_gmt":"2009-07-30T11:27:44","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/conditional-custom-fields-shortcode\/"},"modified":"2009-07-30T20:47:01","modified_gmt":"2009-07-30T20:47:01","slug":"conditional-custom-fields-shortcode","status":"publish","type":"plugin","link":"https:\/\/kea.wordpress.org\/plugins\/conditional-custom-fields-shortcode\/","author":20607520,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"0.5","stable_tag":"trunk","tested":"2.8.2","requires":"2.7","requires_php":"","requires_plugins":"","header_name":"Conditional Custom Fields Shortcode","header_author":"Godfrey Chan (UBC OLT)","header_description":"","assets_banners_color":"","last_updated":"2009-07-30 20:47:01","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"#TODO","header_author_uri":"http:\/\/www.chancancode.com\/","rating":0,"author_block_rating":0,"active_installs":20,"downloads":4010,"num_ratings":0,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation"],"tags":[],"upgrade_notice":[],"ratings":{"1":0,"2":0,"3":0,"4":0,"5":0},"assets_icons":[],"assets_banners":[],"assets_blueprints":{},"all_blocks":[],"tagged_versions":[],"block_files":[],"assets_screenshots":[],"screenshots":[],"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[225,4060,2010,80,975],"plugin_category":[43],"plugin_contributors":[80711,78671],"plugin_business_model":[],"class_list":["post-6251","plugin","type-plugin","status-publish","hentry","plugin_tags-cms","plugin_tags-conditional","plugin_tags-custom-fields","plugin_tags-shortcode","plugin_tags-template","plugin_category-customization","plugin_contributors-godfreykfc","plugin_contributors-oltdev","plugin_committers-ctltwp"],"banners":[],"icons":{"svg":false,"icon":"https:\/\/s.w.org\/plugins\/geopattern-icon\/conditional-custom-fields-shortcode.svg","icon_2x":false,"generated":true},"screenshots":[],"raw_content":"<!--section=description-->\n<p>A series of shortcodes for using custom field values in pages or posts (or in sidebar widgets - via <a href=\"http:\/\/wordpress.org\/extend\/plugins\/widget-logic\/\">Section Widget<\/a>!), which would then allows you to take store the actual data in custom fields while storing the presentation in the page\/post body. This transforms WordPress into an awesome CMS. Keep reading for more inspirations.<\/p>\n\n<h4>Basic Usage<\/h4>\n\n<pre><code>[cf \"custom field name\"]\n<\/code><\/pre>\n\n<p>Example:<\/p>\n\n<pre><code>Picture of the day:\n&lt;img src='[cf \"picture-link\"]' \/&gt;\n<\/code><\/pre>\n\n<p>This would output something like <code>&lt;img src='http:\/\/thesite.com\/something.jpg' \/&gt;<\/code>, assume the post\/page has the custom field \"picture-link\" and its value is \"http:\/\/thesite.com\/something.jpg\". That way, you (or your clients!) would never accidentally take out a div when updating your page because you won't have to touch the page\/post body anymore!<\/p>\n\n<h4>Default Values<\/h4>\n\n<pre><code>[cf \"custom field name\" default=\"display this if the CF is undefined\"]\n<\/code><\/pre>\n\n<p>Example:<\/p>\n\n<pre><code>Contact [cf \"support-email\" default=\"support@mycompany.com\"] if you have questions.\n<\/code><\/pre>\n\n<p>support@mycompany.com will be displayed there if the custom field \"support-email\" is not present in that post\/page.<\/p>\n\n<h4>Simple Template<\/h4>\n\n<pre><code>[cf \"custom field name\" default=\"default value\"]...template...[\/cf]\n<\/code><\/pre>\n\n<p>Example:<\/p>\n\n<pre><code>Price: [cf \"price\" default=\"Pricing information not available yet.\"] USD$%value% [\/cf]\n<\/code><\/pre>\n\n<p>If you cannot use <code>%value%<\/code> as your placeholder text for some reason, you can change it by specifying the placeholder attribute.<\/p>\n\n<p>Example:<\/p>\n\n<pre><code>Price: [cf \"price\" default=\"Pricing information not available yet.\" placeholder=\"__value__\"] USD$__value__ [\/cf]\n<\/code><\/pre>\n\n<h4>Multiple Values<\/h4>\n\n<p>It's smart enough to do the right thing. If your post has the following custom fields:<\/p>\n\n<ul>\n<li>concert-date: Jan 14th<\/li>\n<li>concert-date: Jan 28th<\/li>\n<li>concert-date: Feb 2nd<\/li>\n<\/ul>\n\n<p>Then <code>[cf \"concert-date\"]<\/code> will output <code>Jan 14th,Jan 28th,Feb2nd<\/code>, exactly what you would expect. You can also optionally provide a separator to replace the default (,).<\/p>\n\n<p>Example:<\/p>\n\n<pre><code>Come to one of our concerts on the following dates: [cf \"concert-date\" separator=\" \/ \"]\n<\/code><\/pre>\n\n<p>(=&gt; Jan 14th \/ Jan 28th \/ Feb 2nd)<\/p>\n\n<h4>Sorting<\/h4>\n\n<pre><code>[cf \"custom field name\" sort=\"nosort|asc|dsc|random\" type=\"string|int|integer|float|bool|boolean|date|auto\"]\n<\/code><\/pre>\n\n<p>You can control how it sort the items (when there's more than one) using the sort attribute (default is <code>nosort<\/code>). By default, it would compare them using PHP's comparison operator (i.e. try to cast them into numeric values, or compare them as strings if that failed). However, you can force a type cast by specifying the type attribute (default is <code>auto<\/code>).<\/p>\n\n<h4>Display Single Value<\/h4>\n\n<p>If display multiple values is not what you want it to do, you can use <code>[cf single=\"true\"]<\/code> to force it to display only the first value. Combining what we have learned so far, you can display a single random value by <code>[cf single=\"true\" sort=\"random\"]<\/code>.<\/p>\n\n<h4>Summary<\/h4>\n\n<p>Syntax for <code>[cf]<\/code> shortcode: (default values in parenthesis)<\/p>\n\n<pre><code>[cf \"field-name\" default=\"\" placeholder=\"%value%\" single=\"(false)|true\" separator=\",\" sort=\"(nosort)|asc|dsc|random\" type=\"string|int|integer|float|bool|boolean|date|(auto)\"](OPTIONAL) template[\/cf]\n<\/code><\/pre>\n\n<h4>Conditionals<\/h4>\n\n<p>Conditionals tags is what makes this plugin unique. Here is a list of them:<\/p>\n\n<pre><code>[if-cf-def \"custom field name\"]\n  Do this when \"custom field name\" is defined for this page\/post\n[\/if-cf-def]\n\n[if-cf-ndef \"custom field name\"]\n  Do this when \"custom field name\" is NOT defined for this page\/post\n[\/if-cf-ndef]\n\n[if-cf-eq \"custom field name\" \"value\"]\n  Do this when \"custom field name\" == \"value\"\n[\/if-cf-eq]\n\n[if-cf-neq \"custom field name\" \"value\"]\n  Do this when \"custom field name\" != \"value\"\n[\/if-cf-neq]\n\n[if-cf-lt \"custom field name\" \"value\"]\n  Do this when \"custom field name\" &lt; \"value\"\n[\/if-cf-lt]\n\n[if-cf-gt \"custom field name\" \"value\"]\n  Do this when \"custom field name\" &gt; \"value\"\n[\/if-cf-gt]\n\n[if-cf-let \"custom field name\" \"value\"]\n  Do this when \"custom field name\" &lt;= \"value\"\n[\/if-cf-let]\n\n[if-cf-get \"custom field name\" \"value\"]\n  Do this when \"custom field name\" &gt;= \"value\"\n[\/if-cf-get]\n<\/code><\/pre>\n\n<p>More detailed documentations will be published soon. In the mean time, check out the following examples and the comments in the PHP code to get a rough idea.<\/p>\n\n<h4>Examples<\/h4>\n\n<pre><code>[if-cf-get \"deadline\" \"today\" type=\"date\"]\n    Submit your application &lt;a href='[cf \"submit-link\"]'&gt;here&lt;\/a&gt;.\n[\/if-cf-get]\n\n[if-cf-lt \"deadline\" \"today\" type=\"date\"]\n    Sorry we regret that we cannot take anymore applications.\n[\/if-cf-lt]\n\n[if-cf-def \"discounted-price\" \"discount-expires\" logic=\"and\"]\n    This product is on discount, get it now for [cf \"discounted-price\" \/] [cf \"discount-expires\" default=\"for a limited time\"]before %value%[\/cf]!\n[\/if-cf-def]\n<\/code><\/pre>\n\n<p><strong>Please note: It seems that there is a serious bug in WordPress' shortcode parser that prevents shortcodes from functioning correctly in certain occasions.<\/strong> The developers are hard at work to get this fixed before the 2.8.3 release. (See <a href=\"http:\/\/core.trac.wordpress.org\/ticket\/10082\">#10082<\/a>) Therefore, please do not report any parser related bugs for the moment. (e.g. the shortcode is displayed on the actual page)<\/p>\n\n<!--section=installation-->\n<ol>\n<li>Extract the zip file and drop the contents in the wp-content\/plugins\/ directory of your WordPress installation<\/li>\n<li>Activate the Plugin from Plugins page<\/li>\n<\/ol>","raw_excerpt":"Use custom field values in you pages or posts. With conditional supports which enables basic templating with custom fields.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/kea.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/6251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kea.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/kea.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/kea.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=6251"}],"author":[{"embeddable":true,"href":"https:\/\/kea.wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/ctltwp"}],"wp:attachment":[{"href":"https:\/\/kea.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=6251"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/kea.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=6251"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/kea.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=6251"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/kea.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=6251"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/kea.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=6251"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/kea.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=6251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}