Add custom data (field) to sidebar widgets for later display

Crude code. I have never tried this but I can get you part of the way there. Add a field… add_action( ‘in_widget_form’, function ($instance) { echo ‘<input type=”text” value=”c00l” />’; return null; }, 1 ); And there is a hook that runs on settings update. add_filter( ‘widget_update_callback’, function($instance, $new_instance, $old_instance, $this) { var_dump($instance, $new_instance, $old_instance, … Read more

Display custom widget value in header.php

The Codex is your friend. There’s a the_widget() function for that. <?php the_widget( ‘MY_Widget’, $instance, $args ); ?> Refer to the Codex entry for values for $instance and $args. $instance = array( ‘title’ => ‘Some Title here’, ‘name’ => ‘Some Name here’, ‘show_info’ => true ); $args = array( ‘before_widget’ => ”, // Your value … Read more

Sort posts by custom field value

This did the trick. I had to use ‘_year” <?php $query = new WP_Query(array( ‘post_type’ => array(‘gtcd’,’user_listing’), ‘posts_per_page’ => ‘999’, ‘meta_key’ => ‘_year’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’ ));

How can I output the custom fields wrapping with HTML

There are many things in your code, I don’t know why you implemented like that. In my view the corrected code should be: <?php if ( get_post_meta( $post->ID, ‘the_link’, true ) != ” ) : ?> <span class=”the_one field1″> <a href=”https://wordpress.stackexchange.com/questions/125102/<?php echo esc_attr(get_post_meta( $post->ID,”the_link’, true )); ?>”> <b data-icon=”info” class=”inner-content”><?php echo _e( ‘Content’, ‘theme-text-domain’ ); … Read more

Help setting up a sql query

Ok, if i understand you clearly, then this is the solution // first get the post ids that have the breakfast food type $post_ids = $wpdb->get_col( “SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = ‘type’ AND meta_value=”Breakfast”” ); // now get the food names $stocktypes = $wpdb->get_col( “SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = … Read more