how to display a widget only on a page where the custom field is defined?

If you have a custom field (metadata) attached to a particular post, page or custom post type, you can do something like the following in your page template file: Example example-template-file.php <?php $sidebar_id = ‘my-custom-sidebar-id’; $my_custom_meta_value = get_post_meta(get_the_ID(), ‘my_custom_meta_key’, true); if ( !empty($my_custom_meta_value) && is_active_sidebar($sidebar_id) ) { dynamic_sidebar($sidebar_id); } ?> Notes: dynamic_sidebar, is_active_sidebar

Adding auto-complete to custom gravity field not working

I have solved my problem using below code.So may be helpful for someone.I have tried by reference style for autocomplete <script> var locations=”<?php echo $json;?>”; var locations_array = JSON.parse(locations); locations_array.sort(); function monkeyPatchAutocomplete2() { jQuery(“#result”).remove(); // Don’t really need to save the old fn, // but I could chain if I wanted to var oldFn = … Read more

How to hide a custom field if there is not a value

I believe you might be looking for this: Types Conditional FIelds Display And set each field to display only if not empty. Then you can set up an array of field labels… $fields[‘goal’] = ‘My Goals: ‘; $fields[‘commitment’] = ‘My Commitments :’; // … and so on… Then loop through the fields to display them: … Read more

Pass current post title to a predefined link

Looks like it’s possible to use a placeholder tag, the following is the PHP code using a _custom_link value of http://somelink.com/?ref=%%title%%. <?php // must be within the Loop $ref_slug = strtoupper(sanitize_title_with_dashes(get_the_title())); $regex = ‘(\%\%title\%\%)’; $ref_link = ( get_option(‘_custom_link’) ) ? preg_replace( $regex, $ref_slug, get_option(‘_custom_link’)) : null; echo $ref_link; ?>

Declaring in variables [closed]

You need to call global $variable; before you can use the variable. Try the code below instead for that line. // setup your global scope here global $icon_var; // set the new value in global scope $icon_var = get_post_meta($menu_item->ID, ‘_menu_item_custom’, true); // then use the variable $menu_list .= “\t\t\t\t\t<li><a href=\”$url\”>$icon_var<span>$title</span></a></li>\n”; DYNAMIC GLOBAL VARIABLE NAME If … Read more