• I am using the following within a custom widget

    <?php if ( $title ) echo $before_title . $title . $after_title; ?>
          <?php global $post; $args = array( 'numberposts' => $dis_posts, 'post_type' => 'event', 'orderby' => 'meta_value', 'meta_key' => 'event_time'); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); ?>
          <div class="post">
            <h4><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4>
            <span class="meta"><?php if((get_post_meta($post->ID, "event_date", true))) { ?><?php echo get_post_meta($post->ID, "event_date", true); ?><?php } ?></span>
          </div>
        <?php endforeach; ?>

    But by using the orderby and meta_key functions for sorting by my custom field, it breaks the plugin. Only ordering by default actions does it work. Is there a way to oder by custom field in a widget such as this?

The topic ‘"Global $post" orderby custom field’ is closed to new replies.