Skip to content

Instantly share code, notes, and snippets.

@axxe16
Created January 27, 2023 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axxe16/f5ecdc1a96ff71b98c445499cd91b3ab to your computer and use it in GitHub Desktop.
Save axxe16/f5ecdc1a96ff71b98c445499cd91b3ab to your computer and use it in GitHub Desktop.
Manipolazione del #FEED #RSS di #WORDPRESS aggiunta di CPT e TASSONOMIE
//ORDINA IL FEED
function ek_reverseorder($query_string)
{
return query_posts( $query_string . '&order=DESC&orderby=date' );
}
add_action( 'rss2_head', 'ek_reverseorder' );
//AGGIUNGE uno o più CPT al feed RSS
add_action('pre_get_posts', 'exclude_category' );
function exclude_category( &$wp_query )
// Exclude from loop, archive and feed but not from category page/feed
{ if( is_home() || ( is_feed() && !is_category() ) || ( is_archive() && !is_category() )) { // Exclude from home, feed, but not from category page/feed
set_query_var('post_type', array('post', 'appuntamenti','agenda_ordine')); // Exclude category with ID 120
}
}
//AGGIUNGE TASSONOMIE
add_action('rss2_item', 'yoursite_rss2_item');
function yoursite_rss2_item() {
if (get_post_type()=='listings') {
$fields = array(
'listing_bedrooms',
'listing_city',
);
$post_id = get_the_ID();
foreach($fields as $field) {
if ($value = get_post_meta($post_id,$field,true)) {
echo "<{$field}>{$value}</{$field}>\n";
}
}
$taxonomies = array(
'listing_category',
'listing_type'
);
// Loop through taxonomies
foreach($taxonomies as $taxonomy) {
$terms = get_the_terms($post_id,$taxonomy);
if (is_array($terms)) {
// Loop through terms
foreach ($terms as $term) {
echo "<{$taxonomy}>{$term->name}</{$taxonomy}>\n";
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment