Skip to content

Instantly share code, notes, and snippets.

@ryanhellyer
Last active August 29, 2015 14:05
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 ryanhellyer/e2978bb0e36fff1d5fc9 to your computer and use it in GitHub Desktop.
Save ryanhellyer/e2978bb0e36fff1d5fc9 to your computer and use it in GitHub Desktop.
Allow for addition of extra post-types by providing a filter on the get_posts() arguments.
--- <SharePulse.php>
+++ <SharePulse.php>
@@ -159,14 +159,16 @@
$options = $this->get_sp_options();
- $ids = get_posts(array(
- 'orderby' => 'comment_count',
- 'posts_per_page' => -1,
- 'cache_results' => false,
+ $args = array(
+ 'orderby' => 'comment_count',
+ 'posts_per_page' => -1,
+ 'cache_results' => false,
'update_post_meta_cache' => false,
'update_post_term_cache' => false
- ));
-
+ );
+ $args = apply_filters( 'sp_get_posts_args', $args );
+ $ids = get_posts( $args );
+
wp_enqueue_script( 'sharepulse-build-stats', plugin_dir_url( __FILE__ ).'/js/rebuild.js', array( 'jquery-ui-progressbar', 'jquery', 'underscore' ) );
wp_localize_script( 'sharepulse-build-stats', 'sp_Ajax', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
@ryanhellyer
Copy link
Author

The following code will add support for any custom post-type. This could be modified to allow for an unlimited array of possibilties to filter and limit based on post-types, taxonomies etc.

<?php

/*
 * The SharePulse plugin does not support custom post-types by default.
 * Here we add support for all post-types into the plugin
 */
function iculture_sharepulse_get_posts_arguments( $args ) {
    $args['post_type'] = 'any';
    return $args;
}
add_action( 'sp_get_posts_args', 'iculture_sharepulse_get_posts_arguments' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment