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://ift.tt/1tZ8pSK;
<author>john</author>
<sortDate>20150522</sortDate>
<info><![CDATA[22/23/24 May '15 — Amsterdam, Netherlands]]></info>
</item>
No comments:
Post a Comment