0

Thanks in advance for any help.

My issue is quite simple but a little out of my reach! I'm basically pulling posts from one Wordpress set-up to display on another. Using XML i've created the feed and pulled all of the information out successfully. One issue I am having however is to order the posts as I did in my Wordpress set-up. I have ordered the posts via a custom field "sortin_date", then used a Wordpress loop to order the posts by this date (code below):

WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 4, 'meta_key'=>'sortin_date',  'orderby' => 'sortin_date', 'order' => ASC, 'caller_get_posts'=> -1 ) );

The "sortin_date" field outputs as: YYYYMMDD

However, obviously I can't use a simple Wordpress loop on my php parsing script. My question is, how can I achieve the same loop above with my foreach loop? (code below):

<?php
    $prodFeed = simplexml_load_file('myxmllink.xml');
    foreach ($prodFeed->item as $product):
        $c++;

        $title=$product->title;
        $link=$product->link['href'];
        $info=$product->info;

        if( $c % 2 != 0) { echo '<li>'; }
        else { echo '<li class="hlight">'; }

        echo '<a href="' . $link . '">' . $title . '</a><span class="workshop_date">' . $info . '</span></li>';

        if ($c == 4) break;
    endforeach;
?>

Example XML item (sortDate is the "sortin_date"):

    <item>
                <id>2799</id>
                <title><![CDATA[Fascial Release for Structural Balance:  Fans of the Hips]]></title>
                <link>http://www.thelink.com/</link>
                <author>john</author>
                <sortDate>20150522</sortDate>
                <info><![CDATA[22/23/24 May '15 &mdash; Amsterdam, Netherlands]]></info>
</item>
kala233
  • 549
  • 4
  • 20
  • I was able to resolve this by simply tweaking my XML output to do the sorting work for me, then I didn't need to worry about the sorting from the destination side. However, if anyone wants to answer my question for anyone out there who doesn't have access to the output and needs to do it via the foreach loop. – kala233 Aug 30 '14 at 22:03
  • http://php.net/manual/en/array.sorting.php – Tomás Cot Aug 30 '14 at 23:05

0 Answers0