Support » Plugins » Hacks » Long/complex url being passed as an argument in shortcode not working

  • Resolved wpfan1000


    In the code below if I use:

    [myrssfeeddisplay feedurl=””]

    Then the proper rss feed content is displayed from this source.

    If I use:

    [myrssfeeddisplay feedurl=””]

    ie I use a more complex feed url that includes special characters, I get:

    No items

    Please please help – I have been digging for hours trying to figure this out – obviously it is something about the url but I dont know what and how to fix it.

    Many thanks ahead of time!!

    function myrssfeeddisplay ( $atts, $content = null )
       		extract( shortcode_atts( array(
    			'feedurl' => ''					// Set default values
         	 ), $atts ) );
    		if(function_exists('fetch_feed'))		// Check if the WP function is available
    				include_once(ABSPATH . WPINC . '/feed.php');  // include the required file
    		// Get a SimplePie feed object from the specified feed source:
    		$rss = fetch_feed( $feedurl );
    		if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
        		// Figure out how many total items there are, but limit it to a specified number
    			// Make it an even number in case you display 2 columns of items
        		$maxitems = $rss->get_item_quantity( 6 ); 
        		// Build an array of all the items, starting with element 0 (first element):
        		$rss_items = $rss->get_items( 0, $maxitems );
    		if ( $maxitems == 0 )		// If there are no items in the rss feed
    				$html = 'No items';
    			else					// If there ARE items in the rss feed
    					// Build the $html variable - it must contain all html that is returned out to the page					
    					$html = '<div class = "rssfeedlist">';	// Start of div
    					// Loop through each feed item:
    					foreach ( $rss_items as $item )
    							// Get the url of the item:
    							$url = esc_url( $item->get_permalink() );
    							// Get the title of the item:
                        		$title = esc_html( $item->get_title() );
    							// Create the anchor link of the item:
    							$anchor = '<a href="' . $url . '" target="_blank" >' . $title . '</a>';		
    							// Get the description of the item - for ebay this includes links to the ebay page:
    							$description = $item->get_description();
    							// Add the above for each item to the $html that will be returned to show all items:
    							$html = $html.$anchor.$description;
    					$html = $html.'</div>';	// Add closing tag of rssfeedlist div
    				return $html;	// Return all $html out of shortcode to page
    add_shortcode('myrssfeeddisplay', 'myrssfeeddisplay');
Viewing 4 replies - 1 through 4 (of 4 total)
  • I think you may be being bitten by wptexturize() converting ampersands to the HTML code equivalent.


    As a workaround you could try converting back the feed_url to replace the HTML codes with real ampersands.


    Hi Ian,

    Thanks very much for your time and suggestions.

    I echoed $feedurl in the shortcode above and it does not seem to have converted ampersands to the HTML code equivalent. I checked this in the source code of the page, instead of how the browser may render this, just to make sure.

    I have also noticed that if I take some of the terms out of the lengthy URL – by terms I mean eg “&_fpos=” that it starts to work….

    So I am still trying to figure this out….

    Any further help would be appreciated.

    Hi Ian,

    You were on the right track 🙂

    I discovered that the WP wysiwyg editor converts & to &amp in any url you enter and so you must convert it back.

    So I now use the following to convert it back:

    $feedurl = str_replace("&", "&amp ", $feedurl);

    This works!!!!

    Sorry, in the above str_replace the first two parameters should be swapped, when I pasted in the code WP stripped out some characters and I manually entered them back, but in the wrong parameter.

    I have tried to paste the correct code in this post but WP strips out the characters no matter what i do.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Long/complex url being passed as an argument in shortcode not working’ is closed to new replies.