• Hi All,

    Would love some help with this. here goes…

    I have ‘flutter’ installed for custom fields.
    This is for entering posts as ‘News’ and some as ‘Events’

    All posts that are ‘news’ appear on my main blog page, and posts categorized as ‘events’ appear on my event page I created.

    I do this by using the following code:

    <?php
    if (is_page('events') ) {
    $cat = array(3);
    
    }
    
    $showposts = -1; // -1 shows all posts
    $do_not_show_stickies = 1; // 0 to show stickies
    $args=array(
       'category__in' => $cat,
       'showposts' => $showposts,
       'caller_get_posts' => $do_not_show_stickies
       );
    $my_query = new WP_Query($args); 
    
    ?>
    
    	<?php if( $my_query->have_posts() ) : ?>
    
    		<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    			<?php
    			//necessary to show the tags
    			global $wp_query;
    			$wp_query->in_the_loop = true;
    
    			?>
    
    			<div <?php post_class() ?> id="post-<?php the_ID(); ?>"><small><?php $MyVariableName = get('date');
          $timestamp = strtotime($MyVariableName);
          echo date_i18n('F jS, Y', $timestamp);
          ?></small>
    				<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    
    <? echo get('Event_Date'); ?>
    				<div class="entry">
    					<?php the_content('Read the rest of this entry ?'); ?>
    				</div>
    
    				 <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments ?', '1 Comment ?', '% Comments ?'); ?></p>
    			</div>
    
    		<?php endwhile; ?>
    
    	<?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.</p>
    		<?php get_search_form(); ?>
    
    	<?php endif; ?>
    
    	</div>
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>

    the custom field is ‘date’ and you can see I call it within this script, and it displays the date above each entry.

    My issue is that I would like to arrange my post via this custom field, rather than my publish date. I have tried numerous solutions…

    like the following:
    https://snipplr.com/view/13971/wordpress-sort-order-by-custom-field-for-specific-category/

    https://www.christianschenk.org/projects/wordpress-list-posts-custom-field-plugin/

    https://codex.www.ads-software.com/Displaying_Posts_Using_a_Custom_Select_Query

    …but have had no luck. Any advice would be great.

    Thank you
    Stephen

Viewing 1 replies (of 1 total)
  • So sort by custom field ‘date’
    change

    $args=array(
       'category__in' => $cat,
       'showposts' => $showposts,
       'caller_get_posts' => $do_not_show_stickies
       );

    to

    $args=array(
       'orderby' => 'meta_value',
       'meta_key'=>'date',
       'category__in' => $cat,
       'showposts' => $showposts,
       'caller_get_posts' => $do_not_show_stickies
       );

Viewing 1 replies (of 1 total)
  • The topic ‘Trouble with custom fields and Post ordering’ is closed to new replies.