How do I include a template file while allowing it to render its own dynamic content added via custom box?

You can include any template you want using get_template_part() e.g.: <?php get_template_part(‘navigation’); ?> Using this function also gives you child/parent theme support. Also of note, you could put: <?php get_template_part(‘navigation’,’search’); ?> Which would attempt to load navigation-search.php, but if that isn’t found or doesn’t exist, it will fallback and load navigation.php instead. I use this … Read more

How to show certain data on certain interval of period

Here’s a function you can put in functions.php. function get_current_event() { global $post; $now = get_the_time(‘U’); $year = get_the_time(‘Y’); if($now >= strtotime(“January 1 $year”) && $now < strtotime(“March 1 $year”)) { return get_post_meta($post->ID,’eventA’,true); } if($now >= strtotime(“March 1 $year”) && $now < strtotime(“October 15 $year”)) { return get_post_meta($post->ID,’eventB’,true); } $nextyear = $year+1; if($now >= strtotime(“October … Read more

Hide / Show Custom field depending of the page ID (Magic Field 2)

You can remove meta boxes with the remove_meta_box function: function wpse50430_remove_meta_boxes() { // make sure we’re on an admin screen and `post` is set if( !is_admin() && !isset( $_GET[‘post’] ) ) return; if( $_GET[‘post’] == 99 ): // editing page ID 99 remove_meta_box( ‘pageparentdiv’, ‘page’, ‘normal’ ); endif; } add_action( ‘admin_menu’, ‘wpse50430_remove_meta_boxes’ ); To remove … Read more

get_post_meta returns 0

Change $single back to false, e.g.: <?php $name_text = get_post_meta( 65, ‘name_text’ ); ?> Why? If set to true then the function will return a single result, as a string. If false, or not set, then the function returns an array of the custom fields. This is not intuitive. For example, if you fetch a … Read more

using custom fields on content.php file of my theme

empty will only take variables passed by reference. so empty(some_function()) will never work. See the php docs for more information. <?php if (get_custom_field_value(“signature”,””)) : ?> &mdash; <?php the_category( ‘<span>/</span>’ ); ?> <?php endif; ?> You’re better off just checking for the boolean, like above. The get_custom_field_value function already takes care of making sure you get … Read more

Editing custom fields for comments

I think you’ve way over-complicated things. Assuming private is a checkbox, just check for it being set, and act accordingly. With form $_POST data, a checkbox will send its value if checked, and will send nothing if not checked: if ( isset( $_POST[‘private’] ) ) { update_comment_meta( $comment_id, ‘private’, ‘private’ ); } else { delete_comment_meta( … Read more

Show array of meta_value in Edit Post Coloum

The error was here: (Thank you @Rarst) if ($column_name == ‘custom_checkbox_group_sesso’) { $sesso_occupanti = get_post_meta($post_ID, “custom_checkbox_group_sesso”, true); //check that we have a custom field if ($sesso_occupanti != “”) { // Separate our comma separated list into an array $sesso_occupanti = explode(“,”, $sesso_occupanti); //loop through our new array foreach ($sesso_occupanti as $sesso) { echo $sesso ; … Read more