WordPress.org

Ready to get started?Download WordPress

Forums

A loop based on meta data (5 posts)

  1. jeffeggleston
    Member
    Posted 2 years ago #

    Below is a code I'm using to create a second loop showing a series of posts for movies and plays and whatnot. I am a PHP novice. I have added all of the data on the post pages that is required and yet I get only one post showing up in the loop feed. Sometimes nothing shows up if I change the category (from movies to featured-event). Here's the URL:

    http://library.jeffmeggleston.com/

    [Code moderated as per the Forum Rules. Please use the pastebin]

  2. jeffeggleston
    Member
    Posted 2 years ago #

    This code is based on the following page on WP Recipes:
    http://www.wprecipes.com/how-to-set-post-expiration-datetime-on-your-wordpress-blog
    I've gotten this code to work on the "Movies" page of the site using the following version of the code:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Thank you in advance for your help!!!!!

  3. jeffeggleston
    Member
    Posted 2 years ago #

    I should also note that depending on how I edit the code above (the first one) it occasionally erases the meta data in my database on one or many of the posts. That is irritating.

  4. jeffeggleston
    Member
    Posted 2 years ago #

    This is the code that is not working on the homepage.http://pastebin.com/eU4Rcwr1

    This is the code that works on my "movies" page.
    http://pastebin.com/ATwFigig

  5. AngelEyes
    Member
    Posted 2 years ago #

    not sure if you've seen this, but custom field queries are built into WP_Query and are relatively straight forward. I just used this type of query on a recent website to find a couple "related posts" by posts with the same "author" meta key /value.

    A note:
    the only way I was able to get the query to work was the more extended version that is used for multiple key pairs, even though I was only using one key pair

    $args = array(
    	'post_type' => 'product',
    	'meta_query' => array(
    		array(
    			'key' => 'color',
    			'value' => 'blue',
    			'compare' => 'NOT LIKE'
    		),
    		array(
    			'key' => 'price',
    			'value' => array( 20, 100 ),
    			'type' => 'numeric',
    			'compare' => 'BETWEEN'
    		)
    	)
     );
    $query = new WP_Query( $args );

    http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

Topic Closed

This topic has been closed to new replies.

About this Topic