Skip to main content
updated code to working version
Source Link
Chuck
  • 523
  • 1
  • 9
  • 24

edit 3/2427/2011, working code

<?php
/**
 * Template Name: agentSearch
 */

get_header(); ?>

<div class="fullWidthContent">
    <h1>
        <?php the_title(); ?>
    </h1>
</div>
<div id="agentsContainer">

<?php 
$loop = new WP_Query( array( 
    'post_type' => 'agents',
    'orderby' => 'meta_value',
'meta_key' => 'rw_dname',
    'order'=>'ASC',
    'meta_query' => array(
        array( 'key' => 'dName''rw_dName' )
        ),
    'post__not_in' => array( 98'98' ),
    'posts_per_page' => -1 ) );

$loop2 = new WP_Query( array( 
    'post_type' => 'agents',
    'post__in' => array( 98'98' ) ) );?>
<?php
if($loop->have_posts() || $loop2->have_posts()) { 
    if($loop->have_posts()) { while($loop->have_posts()) { $loop->the_post();?>
<div class="agentContent">
    <div class="agentThumbnail">
        echo<?php the_title
        if ( has_post_thumbnail();
 ) { // check if the post echohas get_post_custom_valuesa Post Thumbnail assigned to it.
        the_post_thumbnail('rw_dName');
}?>
</div>
<div class="agentInfo"> <span class="agentInfoEntry">
        <?php
$meta = get_post_meta(get_the_ID(), 'rw_dname', true);
echo $meta; //Post Contentif you want to show
?>
        }</span> </div>
</endwhilediv>
<?php
        } //endwhile
    }
?>
<?php
if($loop2->have_posts()) { while($loop2->have_posts()) { $loop2->the_post();?>
<div class="agentContent">
    <div class="agentThumbnail">
    echo<?php the_title
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
} 
?>
</div>
    <div class="agentInfo"> <span class="agentInfoEntry">
 echo get_post_custom_values  <?php
$meta = get_post_meta('rw_dName'get_the_ID(), 'rw_dname', true);
echo $meta; // if you want to show
?>
 /       </Postspan> Content</div>
</div>
<?php
        } //endwhile
    }
?>
<?php
} else {
    echo 'No Agents.';
}
?>

<?php get_footer(); ?>

edit 3/24/2011

<?php
/**
 * Template Name: agentSearch
 */

get_header(); ?>

<div class="fullWidthContent">
    <h1>
        <?php the_title(); ?>
    </h1>
</div>
<div id="agentsContainer">

<?php 
$loop = new WP_Query( array( 
    'post_type' => 'agents',
    'orderby' => 'meta_value',
    'meta_query' => array(
        array( 'key' => 'dName' )
        ),
    'post__not_in' => array( 98 ),
    'posts_per_page' => -1 ) );

$loop2 = new WP_Query( array( 
    'post_type' => 'agents',
    'post__in' => array( 98 ) );

if($loop->have_posts() || $loop2->have_posts()) { 
    if($loop->have_posts()) { while($loop->have_posts()) { $loop->the_post();
        echo the_title();
        echo get_post_custom_values('rw_dName');
        //Post Content
        } //endwhile
    }
    if($loop2->have_posts()) { while($loop2->have_posts()) { $loop2->the_post();
        echo the_title();
        echo get_post_custom_values('rw_dName');
        //Post Content
        } //endwhile
    }
} else {
    echo 'No Agents.';
}
?>

<?php get_footer(); ?>

edit 3/27/2011, working code

<?php 
$loop = new WP_Query( array( 
    'post_type' => 'agents',
    'orderby' => 'meta_value',
'meta_key' => 'rw_dname',
    'order'=>'ASC',
    'meta_query' => array(
        array( 'key' => 'rw_dName' )
        ),
    'post__not_in' => array( '98' ),
    'posts_per_page' => -1 ) );

$loop2 = new WP_Query( array( 
    'post_type' => 'agents',
    'post__in' => array( '98' ) ) );?>
<?php
if($loop->have_posts() || $loop2->have_posts()) { 
    if($loop->have_posts()) { while($loop->have_posts()) { $loop->the_post();?>
<div class="agentContent">
    <div class="agentThumbnail">
        <?php 
        if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
        the_post_thumbnail();
}?>
</div>
<div class="agentInfo"> <span class="agentInfoEntry">
        <?php
$meta = get_post_meta(get_the_ID(), 'rw_dname', true);
echo $meta; // if you want to show
?>
        </span> </div>
</div>
<?php
        } //endwhile
    }
?>
<?php
if($loop2->have_posts()) { while($loop2->have_posts()) { $loop2->the_post();?>
<div class="agentContent">
    <div class="agentThumbnail">
    <?php 
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
} 
?>
</div>
    <div class="agentInfo"> <span class="agentInfoEntry">
    <?php
$meta = get_post_meta(get_the_ID(), 'rw_dname', true);
echo $meta; // if you want to show
?>
        </span> </div>
</div>
<?php
        } //endwhile
    }
?>
<?php
} else {
    echo 'No Agents.';
}
?>
updated current state of page
Source Link
Chuck
  • 523
  • 1
  • 9
  • 24

I would like to display all agents a-z, except there is one agent who should always show up last. Ideally I'd like the ordering to be done from the value of a custom field, dName.

I was looking around it seemed that meta_query was the new best way to do this but haven't figured it out yet.

Current code that shows 10 last agents created.

<?php $loop = new WP_Query( array( 'post_type' => 'agents', 'posts_per_page' => 10 ) ); ?>

Thanks for looking.

edit 3/24/2011

<?php
/**
 * Template Name: agentSearch
 */

get_header(); ?>

<div class="fullWidthContent">
    <h1>
        <?php the_title(); ?>
    </h1>
</div>
<div id="agentsContainer">

<?php 
$loop = new WP_Query( array( 
    'post_type' => 'agents',
    'orderby' => 'meta_value',
    'meta_query' => array(
        array( 'key' => 'dName' )
        ),
    'post__not_in' => array( 98 ),
    'posts_per_page' => -1 ) );

$loop2 = new WP_Query( array( 
    'post_type' => 'agents',
    'post__in' => array( 98 ) );

if($loop->have_posts() || $loop2->have_posts()) { 
    if($loop->have_posts()) { while($loop->have_posts()) { $loop->the_post();
        echo the_title();
        echo get_post_custom_values('rw_dName');
        //Post Content
        } //endwhile
    }
    if($loop2->have_posts()) { while($loop2->have_posts()) { $loop2->the_post();
        echo the_title();
        echo get_post_custom_values('rw_dName');
        //Post Content
        } //endwhile
    }
} else {
    echo 'No Agents.';
}
?>

<?php get_footer(); ?>

I would like to display all agents a-z, except there is one agent who should always show up last. Ideally I'd like the ordering to be done from the value of a custom field, dName.

I was looking around it seemed that meta_query was the new best way to do this but haven't figured it out yet.

Current code that shows 10 last agents created.

<?php $loop = new WP_Query( array( 'post_type' => 'agents', 'posts_per_page' => 10 ) ); ?>

Thanks for looking.

I would like to display all agents a-z, except there is one agent who should always show up last. Ideally I'd like the ordering to be done from the value of a custom field, dName.

I was looking around it seemed that meta_query was the new best way to do this but haven't figured it out yet.

Current code that shows 10 last agents created.

<?php $loop = new WP_Query( array( 'post_type' => 'agents', 'posts_per_page' => 10 ) ); ?>

Thanks for looking.

edit 3/24/2011

<?php
/**
 * Template Name: agentSearch
 */

get_header(); ?>

<div class="fullWidthContent">
    <h1>
        <?php the_title(); ?>
    </h1>
</div>
<div id="agentsContainer">

<?php 
$loop = new WP_Query( array( 
    'post_type' => 'agents',
    'orderby' => 'meta_value',
    'meta_query' => array(
        array( 'key' => 'dName' )
        ),
    'post__not_in' => array( 98 ),
    'posts_per_page' => -1 ) );

$loop2 = new WP_Query( array( 
    'post_type' => 'agents',
    'post__in' => array( 98 ) );

if($loop->have_posts() || $loop2->have_posts()) { 
    if($loop->have_posts()) { while($loop->have_posts()) { $loop->the_post();
        echo the_title();
        echo get_post_custom_values('rw_dName');
        //Post Content
        } //endwhile
    }
    if($loop2->have_posts()) { while($loop2->have_posts()) { $loop2->the_post();
        echo the_title();
        echo get_post_custom_values('rw_dName');
        //Post Content
        } //endwhile
    }
} else {
    echo 'No Agents.';
}
?>

<?php get_footer(); ?>
Tweeted twitter.com/#!/StackWordPress/status/50384239824355328
Source Link
Chuck
  • 523
  • 1
  • 9
  • 24

Display agents (custom post type) alphabetically, except one who always shows last.

I would like to display all agents a-z, except there is one agent who should always show up last. Ideally I'd like the ordering to be done from the value of a custom field, dName.

I was looking around it seemed that meta_query was the new best way to do this but haven't figured it out yet.

Current code that shows 10 last agents created.

<?php $loop = new WP_Query( array( 'post_type' => 'agents', 'posts_per_page' => 10 ) ); ?>

Thanks for looking.