Quantcast
Channel: Wordpress Feed - Content Type is automatically changing - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Wordpress Feed - Content Type is automatically changing

$
0
0

i have created a custom rss/xml feed for my wordpress page to list certain jobs - it works, except that the content type is changing automatically and very arbitrary from rss/xml to text/html, which makes it impossible to fetch the feed correctly. I really don't know why or how to reproduce the problem.

Is there something wrong about the code? I don't think so - maybe its du to false configuration of the server or something like that.

Here is the code:

class KIE_XML_Feed{  public function __construct()  {    add_action( 'init', array( $this, 'kie_add_xml_job_feeds' ) );    add_filter( 'feed_content_type', array( $this, 'kie_feed_type'), 10, 2 );  }  function kie_add_xml_job_feeds() {    add_feed( 'joblift', array( $this, 'kie_render_joblift_job_feed' ) );  }  function kie_feed_type( $content_type, $type ) {    if ( 'joblift' === $type ) {      return feed_content_type( 'rss' );    }    return $content_type;  }  /*  *  * Joblift  *  */  function kie_render_joblift_job_feed() {    header( 'Content-Type: application/rss+xml ; charset=' . get_option( 'blog_charset' ), true );    echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?' . '>';    // Start feed    ?><feed xmlns="http://www.w3.org/2005/Atom"><?php    // Query    $job_query = new WP_Query( ['post_type'      => 'jobs','posts_per_page' => -1,'meta_query' => array(        array('key' => 'kie_xml_feed_joblift','value' => '1','compare' => '=','type' => 'numeric'        )      )    ]);    // Loop    if ( $job_query->have_posts() ) {      while ( $job_query->have_posts() ) {        $job_query->the_post();        get_template_part( 'partials/feeds/joblift' );      }    }    // End feed    ?></feed><?php    // Reset    wp_reset_postdata();  }}

Thank you in advance.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images