Question

I know this code is incorrect, but it's a basis of what I am trying to achieve.

I am parsing an xml feed via PHP and running a foreach loop to get a value from a specific key.

Here is the snippet I am using:

$feed = file_get_contents("https://www.feedurl.com/xml"); // Feed URL
$xml = new SimpleXmlElement($feed);

$output = array();
foreach($xml->entry as $entry){
  $attributes = $entry->id->attributes(URI_RSS);
  $im = $entry->children(URI_RSS);                                    

  // Get item's ID
  $id = $entry->id;
  $attr = $id->attributes('im', TRUE);

  $output[] = $attr['id'];
}

$testarray = "'" . implode("', '", $output) . "'"; // Place the 'output' from the foreach into this formation: 'xxx','xxx','xxx',etc    
$lastarray = array($testarray);

$args = array(
  'post_type' => $post_type,
  'post__in'      => $lastarray
);

$wp_query = new WP_Query( $args );

When I echo '$testarray' it displays correctly in the way I had set it up: 'xxx','xxx','xxx',etc

However, trying to place '$testarray' as an array for 'post__in' doesn't work. I know for sure my code isn't set correctly and am not sure how I would do it.

The 'post__in' would be paginated, loading via a infinite loop.

Thanks! Joe.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top