Forums

Pulling specific pages with meta & the loop (13 posts)

  1. whiteorb
    Member
    Posted 1 year ago #

    I have an instance where I'm unable to use post_parent and have already gone too far down the rabbit hole to rework the site's structure. It seems as though using custom fields and the loop to pull pages (not posts) with meta such as "indoor" or "day/night will work well. However, I've tried a number of examples and have read the codex but can't seem to find assistance with how to pull the_title, the_excerpt, and the_post_thumbnail from specific custom fields.

    Any help or ideas would be appreciated?

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    So you've just run a query and a loop?

    <?php query_posts( 'post_type=page&meta_value=indoor' ); ?>
    	<?php if (have_posts()) : ?>
    
    	<?php while (have_posts()) : the_post(); ?>
    
    <?php the_title(); ?>
    <?php the_post_thumbnail(); ?>
    <?php the_excerpt; ?>
    
    	<?php endwhile; ?>
    
    	<?php endif; ?>

    In it's simplest. Would pull pages, with a meta value (not key) of indoor...

    Haven't tested, but just wanna see what you've tried.....

  3. whiteorb
    Member
    Posted 1 year ago #

    I have tried that or something similar. It pulls the thumbnail and the title but not the excerpt.

    Thanks!

  4. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    Oh right.... I think pages do not have excerpts...

    You could run a filter on the_content to limit output I would think...

  5. whiteorb
    Member
    Posted 1 year ago #

    I'm able to do it when not using custom fields and just pulling from the post_parent. I think this code may be messy as well. I simply modified the array to pull the ID from current page.

    <?php
    $args=array(
      'orderby' => 'title',
      'order' => 'ASC',
      'post_type' => 'page',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1,
      'post_parent' => $post->ID
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <?php
    $imageurl = get_post_meta($post->ID, 'imageurl', true);
    if ($imageurl) { ?>
    <?php } else {?>
    					<div class="entry-content">
                        <div style="float:left;">
                        <?php the_post_thumbnail(); ?>
                        </div>
                        <div style="float:right; width:350px;">
    	                    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    			<?php the_excerpt(); ?>
    			<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
    						<?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
                            <?php the_tags('<div> ', ', ', '</div>'); ?>
                        </div>
    					</div><!-- .entry-content -->
        <?php
        }
      endwhile;
    }
    wp_reset_query();
    ?>
  6. whiteorb
    Member
    Posted 1 year ago #

    Opp ok, found the problem <?php the_excerpt; ?> needed to be <?php the_excerpt(); ?>

    Thank you for the help!

  7. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    lol....sorry about the dumb typo!

  8. whiteorb
    Member
    Posted 1 year ago #

    Regarding separating values with a comma. Some of these products are going to have multiple value but the loop only needs to display one at a time. In this instance it would be "indoor" when the product may have "daynight, network, indoor" I read the post that you were kind enough to recommend but I'm unsure how to implement it in this instance.

    http://wordpress.org/support/topic/seperate-multiple-values-in-get_post_meta-with-commas?replies=3

  9. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    so... the product custom field would have a key of "indoor"

    and values of "daynight", "network", "indoor" all assigned

    But you only want a certain value showing/in use? I'm not sure I'm totally following....

  10. whiteorb
    Member
    Posted 1 year ago #

    Sorry, it would have the name=Type and value=indoor, outdoor, etc
    And this loop would pull all devices with the value indoor.

    It doesn't seem to work with I add the comma separated fields.

  11. whiteorb
    Member
    Posted 1 year ago #

    I could really use some help on this one. I've found information on how to create multiple custom fields and how to query multiple types but nothing on how to query multiple values from a single meta_type.

    For example I have the meta_type as "product" and it has the meta_value "indoor, outdoor, daynight" I then have the loop.

    <?php query_posts( 'post_type=page&meta_value=outdoor' ); ?>

    It simply doesn't recognize that outdoor is a value.

    I've tried a number of things (not that I have a perfectly clear understanding) but they all run me in circles and generally break.

    Any ideas or direction would be very useful. Thanks again

  12. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    http://codex.wordpress.org/Function_Reference/get_post_custom_values

    I think the solution may involve this..... that's as far as I've gotten....but figured I'd point you down the path I'm looking at

  13. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    Yeah...I got nuthin...

    I can hold the values in an array..... just not sure how to check if a value exists in the array for use in your loop....

    Hopefully someone else hops in to steer, so I can learn too....

Topic Closed

This topic has been closed to new replies.

About this Topic