Frage

I am displaying contents of an XML file of a search URL from Wordpress using domdocument. Everything works on a normal search url, but when I want the search to be 'exact match' of the phrase, which means I have to put double quotes around the keyphrase, it returns nothing. So how do I get it to work when adding the quotations as shown in the URL below...

    $rss = new DOMDocument();
$rss->load('' . home_url() . '/?s="' . ucfirst($player_data->first_name) . '+' . ucfirst($player_data->last_name) .  '"&post_type=post&feed=rss2');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
    $item = array ( 
        'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
        'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
        'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
        'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
        );
    array_push($feed, $item);
}
//foreach($item as $moment); {
if (!$item==NULL) {
for($x=0;$x<10;$x++) {
    $woohoo = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
    $goto = $feed[$x]['link'];
    $timex = $feed[$x]['desc'];
    $dibidy = date('l F d, Y', strtotime($feed[$x]['date']));
    $str_view_player .=  '<div><strong><a href="'.$goto.'">'.$woohoo.'</a></strong></div>';
    // $str_view_player .=  '<small><em>Posted on '.$dibidy.'</em></small></p>';
    // $str_view_player .=  '<p>'.$timex.'</p>';
} 
    } else {
    $str_view_player .=  '' . ucfirst($player_data->first_name) . ' ' . ucfirst($player_data->last_name) .  ' has not been mentioned yet - but he will soon, we are sure of it!';
    }

Notice the quote marks after s= and before &post_type

War es hilfreich?

Lösung

Either replace your quotation marks with %22 or use urlencode():

$url = '' . home_url() . '/?s="' . ucfirst($player_data->first_name) . '+' . ucfirst($player_data->last_name) .  '"&post_type=post&feed=rss2';
$url = urlencode($url);
$rss->load($url);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top