• I’ve been trying to create a “Featured Posts” widget for my homepage. This would use a category (featured-event) and would display some data from a couple of custom fields (featured_event_info and featured_event_title). I get the loop started fine, but none of the custom field values are showing. Any help would be greatly appreciated. I have some small knowledge of PHP but for the most part I am a designer. Thanks!

    Here’s the code I’m using:

    query_posts('category_name=featured-event&&showposts=3');
    			while (have_posts()) : the_post(); ?>
                <div class="featured-events-post">
                    <a title="<?php echo get_post_meta($post->ID, 'featured_event_title', true); ?>" href="<?php the_permalink() ?>" rel="bookmark">
                        <div class="featured-events-title"><?php echo get_post_meta($post->ID, 'featured_event_title', true); ?></div>
                        <div class="featured-events-shortdata"><?php echo get_post_meta($post->ID, 'featured_event_info', true); ?></a>
                </div>
                <?php endwhile; ?>

    And here’s a link to my development site:
    http://library.jeffmeggleston.com/

Viewing 7 replies - 1 through 7 (of 7 total)
  • You really need to be using get_posts or WP_Query in the widget. query_posts should only be used to modify the main Loop – not create a secondary Loop.

    Thread Starter jeffeggleston

    (@jeffeggleston)

    $the_query = new WP_Query( 'category_name=featured-event' );
                while ( $the_query->have_posts() ) : $the_query->the_post();
                $featured_event_info = get_post_meta($post->ID, "featured_event_info", true);
    			$featured_event_title = get_post_meta($post->ID, "featured_event_title", true); ?>
                <div class="featured-events-post">
                	<a title="<?php echo $featured_event_title; ?>" href="<?php the_permalink() ?>" rel="bookmark">
                        <div class="featured-events-title"><?php echo $featured_event_title; ?>This is where the data should be</div>
                        <div class="featured-events-shortdata"><?php echo $featured_event_info; ?>This is where the info should be</a>
                </div>
                <?php endwhile; ?>

    Ok, so i changed it and I’m still not getting any custom field data.

    Thread Starter jeffeggleston

    (@jeffeggleston)

    This is confusing. I can get all of the title and content data to show but none of the custom field data.

    <a title="<?php echo $featured_event_title; ?>" href="<?php the_permalink() ?>" rel="bookmark">

    Where’s the other end of this link supposed to be?

    Thread Starter jeffeggleston

    (@jeffeggleston)

    $the_query = new WP_Query( 'category_name=featured-event' );
                while ( $the_query->have_posts() ) : $the_query->the_post();
                $featured_event_info = get_post_meta($post->ID, "featured_event_info", true);
    			$featured_event_title = get_post_meta($post->ID, "featured_event_title", true); ?>
                <div class="featured-events-post">
                	<a title='<?php echo $featured_event_title; ?>' href='<?php the_permalink() ?>' rel='bookmark'>
                    <div class="featured-events-title"><?php echo $featured_event_title; ?>This is where the data should be</div>
                    <div class="featured-events-shortdata"><?php echo $featured_event_info; ?>This is where the info should be</div></a>
                </div>
                <?php endwhile; ?>

    I just fixed that.

    Thread Starter jeffeggleston

    (@jeffeggleston)

    Here’s an example of teh data that would show in this case:

    name: featured_event_info
    value: Saturday, Aug. 21 – 8:00pm

    name: featured_event_title
    value: Fiddler On The Roof

    Not sure if that has any bearing on the situation. That is how the data is written in the “value” fields in WordPress.

    Thread Starter jeffeggleston

    (@jeffeggleston)

    I apparently needed to type:

    global $post;

    before the rest of my code. Uugghhh… newbishness….

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Problems displaying custom field data’ is closed to new replies.