Post Indexing Does What?

Ok. I'm sort of clueless, but I'm guessing the Post Indexer plugin makes it possible to do something like MarketPress does where each person has their own posts on their subsite and they can all show on the main site.

How do I do this using the plugin? All I have done is installed the plugin and created a few posts on a sub site to see where they show up and I can not find it.

I would like to do what is done with MarketPress except just with regular posts and a Custom Post Type.

  • DavidM

    Hi Eric,

    Post Indexer takes care of the indexing of posts sitewide, then it's basically up to other plugins to do things with that indexed list. Those other plugins are all listed on the project page as follows:
    https://premium.wpmudev.org/project/post-indexer

    So for instance, the Recent Global Posts Widget lets you display the recent sitewide posts in a widget.
    https://premium.wpmudev.org/project/recent-global-posts-widget

    And you can use any combination of those other plugins to do various things with that indexed list. Just to note though, currently, Post Indexer doesn't do anything with custom taxonomies, but it does index the custom post types themselves.

    Hope that's clear, let me know if you have further questions!

    -David

  • DavidM

    Hi Eric,

    Sure, you can take a look at pretty much any of the Post Indexer based plugins and see examples, but they generally use queries like the following from the Recent Global Post Widget:

    function get_post_types() {
    	global $wpdb;
    	$sql = $wpdb->prepare( "SELECT post_type FROM " . $wpdb->base_prefix . "site_posts GROUP BY post_type" );
    	$results = $wpdb->get_col( $sql );
    	return $results;
    }

    And to get ALL posts from your network, you could maybe use something as simple as this:
    $sql = $wpdb->prepare( "SELECT * FROM " . $wpdb->base_prefix . "site_posts" );

    In post-indexer.php, you'll see the creation of the database table used for all of this and you can use any of the data elements to further restrict your query:

    site_post_id bigint(20) unsigned NOT NULL auto_increment,
    blog_id bigint(20) default NULL,
    site_id bigint(20) default NULL,
    sort_terms text,
    blog_public int(2) default NULL,
    post_id bigint(20) default NULL,
    post_author bigint(20) default NULL,
    post_title text,
    post_content text,
    post_content_stripped text,
    post_terms text,
    post_permalink text,
    post_published_gmt datetime NOT NULL default '0000-00-00 00:00:00',
    post_published_stamp varchar(255) default NULL,
    post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00',
    post_modified_stamp varchar(255) default NULL,
    post_type varchar(20) default 'post',

    Cheers,
    David

  • Eric G.

    Sorry for bugging you guys so much. Am figuring out a few simple concepts that I know will help down the road.

    Am using the business feature theme. On the main page which calls the content-rows.php file. I would like start with this group of posts and then can use it on other pages as well.

    For the time being, have taken out the selection part to select which category to use there.

    This code is what I removed:

    <?php
    	$featured_category = get_option('dev_businessfeature_feature_cat');
    	$featured_number = get_option('dev_businessfeature_feature_number');
    	$featured_title = get_option('dev_businessfeature_feature_title');
    ?>
    <?php
    	if ($featured_category != ""){
    		?>
    		<h2 class="main-header"><?php stripslashes($featured_title); ?></h2>

    And I attempted to add the code you gave above in it's place:

    <?php function get_post_types() {
    	global $wpdb;
    	$sql = $wpdb->prepare( "SELECT * FROM " . $wpdb->base_prefix . "site_posts" );
    	$results = $wpdb->get_col( $sql );
    	return $results;
    } ?>

    Then I just get an error:

    Fatal error: Cannot redeclare get_post_types() (previously declared in /home/rummagey/public_html/wp-includes/post.php:846) in /home/rummagey/public_html/wp-content/themes/business-feature/library/components/content-rows.php on line 6

  • DavidM

    Hi Eric,

    The Recent Global Post Widget already uses the function name get_post_types(), so you'd have to use a different name in order for that to work.

    What I tend to do is use my initials to prefix functions names, so dm_get_post_types(), though any name other than a function name already in use should work just as well.

    Just to note, this is one powerful plugin because of the customization capabilities and I'm eager to see how this all comes along. :slight_smile:

    Cheers,
    David

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.