[resolved] Long/complex url being passed as an argument in shortcode not working (5 posts)

  1. wpfan1000
    Posted 2 years ago #

    In the code below if I use:

    [myrssfeeddisplay feedurl="http://feeds2.feedburner.com/Steadyhand"]

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

    If I use:

    [myrssfeeddisplay feedurl="http://www.ebay.ca/sch/rss/?_sadis=200&_ipg=50&LH_SALE_CURRENCY=0&_sacat=0&_samihi=&_samilow=&_fpos=&_ftrt=901&_udhi=&_oexkw=&_sabdhi=&_ftrv=1&_udlo=&_sabdlo=&_adv=1&_sop=12&_dmd=1&_okw=&_fsct=&_nkw=camry&_rss=1&rt=nc"]

    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');
  2. ianhaycox
    Posted 2 years ago #

    I think you may be being bitten by wptexturize() converting ampersands to the HTML code equivalent.

    See http://wordpress.org/support/topic/wptexturize-convert-ampersands-in-script-tags?replies=1

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


  3. wpfan1000
    Posted 2 years ago #

    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.

  4. wpfan1000
    Posted 2 years ago #

    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!!!!

  5. wpfan1000
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.