WordPress.org

Ready to get started?Download WordPress

Forums

PubSubHubbub
[resolved] Custom Post Types and custom feeds (2 posts)

  1. estepix
    Member
    Posted 1 year ago #

    Hi there,

    After many attempts and headaches I realised that your plugin does not notify custom post types to the hubs configured, only regular posts and comments are notified!!!

    I came up with the following solution for my custom post type and it's working great so thought I should share it:

    /* check if the notifying function is available */
    if( function_exists( 'pshb_publish_to_hub' ) ) {
    
        // function that is called whenever a new post is published
        function pshb_publish_myCustomPostType($post_id) {
          // we want to notify the hub for every feed
          $feed_urls = array();
          $feed_urls[] = get_bloginfo('atom_url');
          $feed_urls[] = get_bloginfo('rss_url');
          $feed_urls[] = get_bloginfo('rdf_url');
          $feed_urls[] = get_bloginfo('rss2_url');
          $feed_urls[] = 'http://example.com/mycustom/feed';
          // customize default feeds
          $feed_urls   = apply_filters('pshb_feed_urls', $feed_urls);
    
          pshb_publish_to_hub($feed_urls);
    
          return $post_id;
        }
        add_action('publish_myCustomPostType', 'pshb_publish_myCustomPostType');
    }

    Edit: you can add this snippet to your theme's functions.php

    You only need to replace "myCustomPostType" with your own Custom Post Type slug.
    Also, since currently only the root feed URLs are notified, you can add as many custom feeds as you want with:
    $feed_urls[] = 'http://example.com/mycustom/feed';

    Hope it helps!

    http://wordpress.org/extend/plugins/pubsubhubbub/

  2. estepix
    Member
    Posted 1 year ago #

    I missed it the first time round, but I realise now that for custom feeds you are better off using the filter hook enabled by the plugin guys:

    $feed_urls   = apply_filters('pshb_feed_urls', $feed_urls);

    Thanks for that guys!!!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic