Jon Imms
asked on
Remove hyperlink from an WordPress Rss feed.
Hey guys, I am having a glitch with my RSS feed. One of the nodes, outputs as a hyperlink (which is a google map location). Majority of the people pulling it's no problem, but for some, it's causing a problem. How could I remove the hyperlink, but still keep the location?
the node in question is line 102 <category><?php the_job_location(); ?></category>
https://cretecarrier.com/f eed/huntfe ed
the node in question is line 102 <category><?php the_job_location(); ?></category>
https://cretecarrier.com/f
<?php
/**
* Template Name: Custom RSS Template - huntfeed
*/
$postCount = 500; // The number of posts to show in the feed
$cacheFile = "rsscache/huntfeed.rss";
if(!file_exists(dirname($cacheFile)))
{
mkdir(dirname($cacheFile));
}
$posts_per_page = 50;
$paged = 0;
$theres_more = true;
$rss_items = array();
if(file_exists($cacheFile) && !isset($_GET["reset"]))
{
$rss_items = json_decode(file_get_contents($cacheFile),true);
if($rss_items == null) { $rss_items = array(); }
}
$charset = get_option( 'blog_charset' );
header( 'Content-Type: ' . feed_content_type( 'rss-http' ) . '; charset=' . $charset, true );
?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
<?php do_action('rss2_ns'); ?>>
<channel>
<title><?php bloginfo_rss( 'name' ); ?> Hunt Transportation Job Feed</title>
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
<link><?php bloginfo_rss('url'); ?></link>
<description><?php bloginfo_rss('description'); ?></description>
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
<language>en</language>
<sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod>
<sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency>
<?php do_action('rss2_head'); ?>
<?php
while($theres_more)
{
$result = query_posts( array(
'post_type' => 'job_listing',
'paged' => $paged,
'posts_per_page' => $posts_per_page,
'tax_query' => array(
array(
'taxonomy' => 'job_listing_type', //or tag or custom taxonomy
'field' => 'id',
'terms' => array('499')
)
)
) );
$number_of_results = count($result);
while(have_posts())
{
// Get the next post
the_post();
// Check the cache
if(isset($rss_items[$post->ID]) && (strtotime($rss_items[$post->ID][0]) == strtotime($post->post_modified)))
{
// We have a cached item with the same modified date
echo $rss_items[$post->ID][1];
}
else
{
// Either the item isn't cached or the last-modified date has changed
ob_start();
?>
<item>
<title><?php the_title_rss(); ?></title>
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
<guid><?php the_permalink_rss(); ?></guid>
<description><![CDATA[<?php the_excerpt(); echo do_shortcode( '[Qualifications]' ); echo do_shortcode( '[about-hunt]' ); ?>]]></description>
<?php
$mystr=get_the_term_list( $post->ID, 'job_listing_category');
$myseperator=',';
$mycount=0;
$drivertype='';
while(strstr($mystr,">")){
$temp_a=strpos($mystr,">")+1;
$temp_b=strpos($mystr,"<",$temp_a);
$value_length=$temp_b-$temp_a;
$value=substr($mystr,$temp_a,$value_length);
$mystr=substr($mystr,($temp_b+4));//add the number of characters in "</a>" which is 4
if($mycount>0){$drivertype.=$myseperator;}
$drivertype.=$value;
$mycount++;
}
?>
<category><![CDATA[<?php echo $drivertype; ?>]]></category>
<category><![CDATA[<?php wpjm_the_job_types() ?>]]></category>
<category><?php the_job_location(); ?></category>
<?php
$mystr=get_the_term_list( $post->ID, 'states');
$temp=strpos($mystr,">");
$states=str_replace("</a>","",substr($mystr,$temp+1));
?>
<category><?php echo $states; ?></category>
<category>United States</category>
<?php rss_enclosure(); ?>
<?php do_action('rss2_item'); ?>
</item>
<?php
// Get the item's RSS content and add it to the array
$rss_item = ob_get_flush();
$rss_items[$post->ID] = array($post->post_modified, $rss_item);
}
}
// Save our updates after every page
file_put_contents($cacheFile, json_encode($rss_items));
// Check to see if there are more pages
$theres_more = ($number_of_results == $posts_per_page);
$paged++;
}
?>
</channel>
</rss>
ASKER
so in the RSS feed, the location appears like this. Some vendors are saying it just pulls up a big Google map on the page they are pulling too. I just want it to output<category>Wheatland, WY, United States</category> with no hyperlink.
<category><a class="google_map_link" href="http://maps.google.com/maps?q=Wheatland%2C+WY%2C+United+States&zoom=14&size=512x512&maptype=roadmap&sensor=false" target="_blank">Wheatland, WY, United States</a></category>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That worked great, thank you.
ASKER
https://www.experts-exchange.com/questions/29112042/Remove-hyperlink-from-an-WordPress-Rss-feed.html?anchorAnswerId=42642376#a42642376
Hey gr8gonzo, A vendor is now asking if we can modify the output of the location, to just City/State. I see you suggested i put var_dump($post); die(); to check to see of their is other fields. Where would i put this in the code to check?
Hey gr8gonzo, A vendor is now asking if we can modify the output of the location, to just City/State. I see you suggested i put var_dump($post); die(); to check to see of their is other fields. Where would i put this in the code to check?
Try this:
BEFORE:
ob_start(); the_job_location(); $the_job_location = ob_get_clean();
AFTER:
ob_start(); the_job_location(); $the_job_location = ob_get_clean();
if(strpos($the_job_locatio n, "Wheatland") !== false)
{
if(!file_exists("/tmp/samp le_rss_pos t.txt"))
{
file_put_contents("/tmp/sa mple_rss_p ost.txt", var_export($post, true));
}
}
That should create a single "sample" export of the $post variable into a file /tmp/sample_rss_post.txt, so you can inspect it.
BEFORE:
ob_start(); the_job_location(); $the_job_location = ob_get_clean();
AFTER:
ob_start(); the_job_location(); $the_job_location = ob_get_clean();
if(strpos($the_job_locatio
{
if(!file_exists("/tmp/samp
{
file_put_contents("/tmp/sa
}
}
That should create a single "sample" export of the $post variable into a file /tmp/sample_rss_post.txt, so you can inspect it.
ASKER
Doesn't seem to create a file.
Edit is now
Edit is now
WP_Post::__set_state(array(
'ID' => 21282,
'post_author' => '4',
'post_date' => '2018-06-25 15:54:03',
'post_date_gmt' => '2018-06-25 20:54:03',
'post_content' => '[av_one_half first min_height=\'\' vertical_alignment=\'\' space=\'\' custom_margin=\'\' margin=\'0px\' padding=\'0px\' border=\'\' border_color=\'\' radius=\'0px\' background_color=\'\' src=\'\' background_position=\'top left\' background_repeat=\'no-repeat\' animation=\'\' mobile_breaking=\'\' mobile_display=\'\']
[av_textblock size=\'\' font_color=\'\' color=\'\' av-medium-font-size=\'\' av-small-font-size=\'\' av-mini-font-size=\'\' av_uid=\'av-jgo3gylt\' custom_class=\'\' admin_preview_bg=\'\']
[flatbed-otr-14] [hunt-benefits] [hunt-qualifications] [about-hunt]
[/av_textblock]
[/av_one_half]
[av_one_half min_height=\'\' vertical_alignment=\'\' space=\'\' custom_margin=\'\' margin=\'0px\' padding=\'0px\' border=\'\' border_color=\'\' radius=\'0px\' background_color=\'\' src=\'\' background_position=\'top left\' background_repeat=\'no-repeat\' animation=\'\' mobile_breaking=\'\' mobile_display=\'\']
[av_sidebar widget_area=\'job-listing\']
[/av_one_half]',
'post_title' => 'Home Bi-Weekly, National OTR Flatbed Truck Driving Job – Wheatland, WY',
'post_excerpt' => '[flatbed-otr-14] [hunt-benefits]',
'post_status' => 'publish',
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_password' => '',
'post_name' => 'two-week-flatbed-otr-fleet-wheatland-wy',
'to_ping' => '',
'pinged' => '',
'post_modified' => '2018-07-13 11:01:34',
'post_modified_gmt' => '2018-07-13 16:01:34',
'post_content_filtered' => '',
'post_parent' => 0,
'guid' => 'https://cretecarrierdev.local/?post_type=job_listing&p=21282',
'menu_order' => 0,
'post_type' => 'job_listing',
'post_mime_type' => '',
'comment_count' => '0',
'filter' => 'raw',
))
ASKER
could we strip the location further? We are stripping the link so it outputting like this <category> Wheatland, WY, United States</category>. Could we have a function which would strip after the second , so <category> Wheatland, WY</category>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
2. "but for some it's causing a problem" - This needs some clarification. Who are the "some" and what is the "problem" that they're reporting (specific error messages would be helpful) ?