Jump to content
bigmuddyfoot

php sort for each loop

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/

Share this post


Link to post
Share on other sites

Where does get_posts() from? It's not a php function.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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? http://www.w3schools...looping_for.asp

Edited by niche

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Good to know. Thanks JSG.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...