Jump to content

php sort for each loop


bigmuddyfoot

Recommended Posts

Hey everyone here is what i have so far.....

<?php$posts = get_posts('numberposts=10&order=DESC&category=68&orderby=post_title');foreach ($posts as $post) : start_wp(); ?><?php echo "<hr>"; ?><?php echo the_event_end_date( $id, $showtime, $dateFormat); ?><?php echo "<hr>"; ?><?php the_title(); ?><?php the_excerpt(); ?><?phpendforeach;?>

I need the the_excerpt and the the_title to sort in order from soonest to later. (event happening soonest to the one happening later that year)This code the_event_end_date( $id, $showtime, $dateFormat); displayed the event date in this format....June 16, 2013How can i sort this I am out of ideas???PLz HELP!!!!http://wordpress.org/extend/plugins/the-events-calendar/

Link to comment
Share on other sites

Where does get_posts() from? It's not a php function.
It is a wordpress function there is an include file that handles this. The code i posted does work just dont know how to handle the ordering portion.
Link to comment
Share on other sites

It seems to me you should change the orderby value, but I really don't know. You might do better asking a wordpress forum. People there do this stuff every day. I haven't tweaked my wordpress site in a few years.

Link to comment
Share on other sites

It seems to me you should change the orderby value, but I really don't know. You might do better asking a wordpress forum. People there do this stuff every day. I haven't tweaked my wordpress site in a few years.
I have posted there just waiting on a responce from them. Thought i would give here a try. The problem with changing the orderby it does it by the mysql db and not the event date...The event date is in a special field.
Link to comment
Share on other sites

Also, please review the code for a foreach loop and compare it to yours. Where are your curly brackets among other things?
Control structures in PHP have alternate syntax that doesn't use brackets, Wordpress uses the alternate syntax all over the place. Instead of brackets there is a colon and endforeach statement. For, if, while, and switch have the same alternate syntax. http://php.net/manual/en/control-structures.alternative-syntax.php
The problem with changing the orderby it does it by the mysql db and not the event date...The event date is in a special field.
Wordpress has to support what you're trying to do, or else you need to use a workaround or change Wordpress. The get_posts function includes the query string to use, so that's what you have to change. If you can't change that for your situation then you need to use a different method from get_posts, maybe querying the database yourself. Otherwise, if the event date field is in the same table as the rest of the post data then you just need to know the name of the field to use in the query.
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...