WordPress.org

Ready to get started?Download WordPress

Forums

Custom Field with Recent Posts (3 posts)

  1. Raquel Wilson
    Member
    Posted 5 years ago #

    I would like to have a recent post listing on the front page of my WP-powered site but I'd like it to be something like this

    News

    photo (entry #2)
    date (entry #2)
    headline (entry #2

    date (entry #1)
    headline (entry #1)

    I know this can be done using a PHP widget plugin, but I'm wondering if there is a recent posts plugin that will allow you to customize with a custom field.

    Any suggestions?

  2. seborgarsen
    Member
    Posted 4 years ago #

    <h3>Latest Instrumentals:</h3>
    			    <ol>
    
    				<?php
    				 $restriction1 = 'Vocal';
    				 $restriction2 = 'BackCatalog';
    				 $restriction3 = 'post_date';
    				 $value1 = 'None';
    				 $value2 = 'No';
    
    				 $querystr = "
    					SELECT * FROM $wpdb->posts
    					LEFT JOIN $wpdb->postmeta AS $restriction1 ON(
    					$wpdb->posts.ID = $restriction1.post_id
    					AND $restriction1.meta_key = '$restriction1'
    					)
    					LEFT JOIN $wpdb->postmeta AS $restriction2 ON(
    					$wpdb->posts.ID = $restriction2.post_id
    					AND $restriction2.meta_key = '$restriction2'
    					)
    					WHERE $wpdb->posts.post_status = 'publish'
    					AND $restriction1.meta_value = '$value1'
    					AND $restriction2.meta_value = '$value2'
    					LIMIT 10
    					";
    
    					$pageposts = $wpdb->get_results($querystr, OBJECT);
    
    					if ($pageposts):
    						foreach ($pageposts as $post):
    							setup_postdata($post); ?>
    							<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    						<?php  endforeach;
    					endif;
    					?>
    
    				</ol>
  3. seborgarsen
    Member
    Posted 4 years ago #

    where Vocal and BackCatalog are custom fields. Hope this helps.

Topic Closed

This topic has been closed to new replies.

About this Topic