WordPress.org

Ready to get started?Download WordPress

Forums

WordPress MU Sitewide Tags Pages
Getting BuddyPress and sitewide tags to play nicely (46 posts)

  1. DoctorDR
    Member
    Posted 3 years ago #

    I've searched through posts and conversations on the usual forums, but cannot find an answer to the issue of duplicate entries in the BP activity stream after installing sitewide tags.

    I have SWT using the main site as the tags site, so clearly the activity stream is showing both the original post (on a user site) and the ghost of a post that is being created on the tag site (i.e. my main site) at the same time.

    I looked at Burt’s patch on trac, (which is 2 years old now) but when I tried the patch in bp-blog.php I found that a patch was already applied in BP 1.2.8 (albeit in a slightly different form).

    At the moment all I want to do is stop the duplicates being displayed in the activity stream (i.e. hide the tag blog occurance), and would be happy enough to settle for filtering them out in the activity stream. Btw, there is always 'two' entries with the 1st entry being the 'site blog' and the 2nd being the 'originating blog'.

    I’ve tried checking if ‘blog_id’ is equal to ‘tag_blog_id’ and then applying this fix to /activity/entry.php, but by the time it reaches the activity stream it seems both blog_id and tag_blog_id fields are the same, so I need a more accurate filter - or maybe the filter needs applied at the bp-blog-php stage.

    Has anyone got a working hack they’d like to share?

  2. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 3 years ago #

    There's a plugin for that: http://wpmututorials.com/plugins/turn-off-sitewide-tags-on-special-blogs/

    Just enable that on your BP home site.

  3. DoctorDR
    Member
    Posted 3 years ago #

    Thanks Ron, I will try it out now.

    Another 'tiny' issue that I'm wrestling with is integrating the wootumblog plugin with STW. The use case is as follows;

    The wootumblog plugin - http://www.woothemes.com/support/wootumblog/ - uses a custom taxonomy and is working fine on both my main blog and user blogs - but the taxonomy type (i.e. photo, video, quote) is not making it through the STW filter when displayed on the homepage of our main blog. The posts get through, but the custom type is not recognised and therefore defaults to 'article'.

    I'm still getting my head around the architecture of custom post types - any suggestions?

  4. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 3 years ago #

    See this post: http://wpmututorials.com/plugins/sitewide-tags-update/

    We have quite a few posts with info on SWT. You should be able to find them all by using our search for "sitewide tags'.

  5. DoctorDR
    Member
    Posted 3 years ago #

    Thanks Ron.

    As I've been looking through the sitewide-tags.php file I noticed the following line of code which looks like it may be a typo..

    LINE 552: add_filter( 'sitewide_tags_allowed_post_types', 'sitewide_tages_pages_filter' );

    Shouldn't the filter be 'sitewide_tags_pages_filter' ?

  6. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 3 years ago #

    Nice catch.

    That's what the function is called, so changing just that line would give you an error.

    I updated the dev version and removed the typo in the function name and changed the filter.

  7. DoctorDR
    Member
    Posted 3 years ago #

    Ron, sorry to ask a really simple question but where do I add the filter in order to include the custom taxonomy within the SWT blog? I have worked with WP for years, but this is the first time I've used custom taxonomies.

    Here's the filter to be added:

    add_filter( 'sitewide_tags_custom_taxonomies', array(&$this, 'tumblog') );

    Do I add it in sitewide-tags.php within the sitewide_tags_post function? And I presume I should re-run 'Populate Posts'?

    I've checked to ensure it's the correct taxonomy using <?php $tumblog_list = get_the_term_list( $post_id, 'tumblog', '' , '|' , '' ); echo $tumblog_list; ?>

    So can see that the custom taxonomy exists in the source blog posts before being aggregated.

  8. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 3 years ago #

    sorry to ask a really simple question but where do I add the filter in order to include the custom taxonomy within the SWT blog

    If you've written a class then add the filter in the constructor of your class.

  9. DoctorDR
    Member
    Posted 3 years ago #

    Thanks Ron, unfortunately I don't actually know what you mean when you say

    "If you've written a class then add the filter in the constructor of your class."

    I have not previously worked with constructors and classes.

    If you get a moment to elaborate any further (i.e. put this section of code in this file) then it would be much appreciated, otherwise I'll ask someone more experienced than me to translate.

  10. DoctorDR
    Member
    Posted 3 years ago #

    Ron, this is the section of code that I am adding to my sub-sites' functions.php file.

    // Custom Taxonomy Tumblog Filter
    add_action('pre_get_posts', 'woo_taxonomy_tumblog_filter' ); 
    
    function woo_taxonomy_tumblog_filter( $query ) {
    
      global $wp_query;
    
      if ($query->is_home || $query->is_front_page) {
    
      	$query->set('tax_query', array(	'taxonomy' => 'tumblog'	));
    
      	$query->parse_query();
      }
    
      return $query;
    
    }
    add_filter( 'sitewide_tags_custom_taxonomies', 'woo_taxonomy_tumblog_filter' );

    It doesn't seem to work - i.e. the taxonomy type still doesn't respond to a simple query on the main site.

    Please let me know if I'm heading in the right direction - I've been trading emails with the wootumblog main developer (jeffikus) and once we've cracked it will share with the community how to recreate the function.

  11. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 3 years ago #

    Please let me know if I'm heading in the right direction

    No, that's not the right direction. It looks like you are trying to alter the WP query on the main site by adding a filter to the sub site.

    From http://wpmututorials.com/plugins/sitewide-tags-update/

    Custom taxonomies use a similar filter

    add_filter( 'sitewide_tags_custom_taxonomies', 'my_swt_custom_tax_filter' )

    The filter passes an array formatted like array( 'post_format', 'subject' ).

    That means what is passed to your filter is an array (not a WP Query object) and you add elements to that array:

    function my_swt_custom_tax_filter( $taxonomies ) {
    $taxonomies[] = 'tumblog';
    return $taxonomies;
    }
    add_filter( 'sitewide_tags_custom_taxonomies', 'my_swt_custom_tax_filter' );

    Your main site has to have a theme that supports the tumblog taxonomy.

  12. DoctorDR
    Member
    Posted 3 years ago #

    Ron, thanks for clarifying that.

    Both my sub site and main site use the same theme - a modified version of BP Default and the tumblog plugin is activated on the main site, whilst I have added its posting functionality within the functions.php in my sub sites.

    So the tumblog functionality works perfectly in both main and sub-sites - the only problem is that the sub-site taxonomies are filtered out by the sitewide tags plugin and therefore when I display a list of posts from across the network, only those from the main site are recognised as tumblog posts.

    So where do I place the above filter? In my main site's functions.php or sub site? Or perhaps a plugin as I noted on Boone Gorges blog - http://teleogistic.net/2010/08/enabling-popularity-contest-for-wordpress-networkwide-use/comment-page-1/#comment-14150

  13. DoctorDR
    Member
    Posted 3 years ago #

    Okay, I have created a plugin and then network activated it on the main site.

    <?php
    /*
    Plugin Name: SWT Custom Taxonomy
    Plugin URI: http://skiddnet.com
    Description: Addition of new custom taxonomies to the wpmu sitewide tags plugin.
    Version: 1.0
    Author: CitizenSlide
    Author URI: http://skiddnet.com
    License: GPL2
    */
    
    function my_swt_custom_tax_filter( $taxonomies ) {
    $taxonomies[] = 'tumblog';
    return $taxonomies;
    }
    add_filter( 'sitewide_tags_custom_taxonomies', 'my_swt_custom_tax_filter' );
    ?>

    Still no sign of those taxonomies. Thanks for all your help (and patience) thus far, I'll keep reading and searching for additional clues.

  14. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 3 years ago #

    That won't have any effect on existing posts. It will only apply to new ones.

  15. DoctorDR
    Member
    Posted 3 years ago #

    I've tested it on both existing (after re-populating posts into the tag blog) and new posts and I'm still not seeing any effect.

    Need to go live today, so unfortunately may have to unravel the sitewide functionality from the design.

  16. DoctorDR
    Member
    Posted 3 years ago #

    I can appreciate how tedious it can be to try and solve one case, but what would be really useful is some real life examples. Most people just need to see and/or recreate a working scenario before we achieved that 'Eureka' moment with our own problems.

    If you find the time in future, perhaps you could illustrate on wpmututorials how to adapt SWT to use custom posts types, custom taxonomies and custom fields. Perhaps then other developers could contribute their own solutions and we'd have a knowledge base for the less experienced developers to use. Just a thought.

  17. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 3 years ago #

    perhaps you could illustrate on wpmututorials how to adapt SWT to use custom posts types, custom taxonomies and custom fields.

    I did describe how to use those filters in the post I linked to above. Unfortunately, I don't have the tumblog theme, so I don't know what it does. I was guessing at what to do in the filter based on the code you had posted above.

    I verified that both the custom post type & custom taxonomies filters work correctly per what's in my post. To use them you need to know what the post type is and what the taxonomy name is.

  18. DoctorDR
    Member
    Posted 3 years ago #

    Ron, I appreciate that you've told me what to do, but despite trying every variation I can think of I've been unable to make it work. I must have searched every post written on SWT and have yet to find anyone who's added a filter to enable a custom taxonomy, so I feel like I'm pioneering.

    Here's what I can see in the database. When a tumblog post is created in blog_id 9, the wp_9_posts and wp_9_postmeta are updated and then 'two' records are added to the wp_9_term_relationships table, where object_id is the post_id, and the first record reflects the category term_id whilst the second record reflects the tumblog taxonomy term_id (in this case '4' which means it's an image post).

    At the same time identical updates are made in the tags blog (my main site blog), however the main tag blog's wp_term_relationship table contains only the first entry (for the post's category) and not the second entry which would reflect the tumblog custom taxonomy term.

    By following the updates through I can see that everything updates fine and the SWT plugin serves its purpose, EXCEPT I lose the custom taxonomy within the main tag blog.

    I've enabled the plugin as posted above, and tried some variations including amending line 2 to say..

    $taxonomies['tumblog'] = true;

    I am at a dead end and can only conclude that (a) either the inbuilt custom taxonomy function within SWT doesn't work, or that the add filter function is incorrect.

    As a workaround I've been trying to find a way of getting the taxonomy term within the ’sitewide_tags_post’ function of SWT and then update the tag blog’s post meta with an entry, but I've been unable to return the term name (or ID) despite using get_the_term_list,get_the_terms, get_terms or even wp_get_object_terms.

    My lack of experience with custom taxonomies and filters is clearly limiting my ability to solve this issue. It's such a simple issue, but it's halted the whole project.

    Does any of this make sense to you, and do you have any further suggestions?

    How about a quick suggestion for how I might hard-code a fix into the plugin to pass thru my custom taxonomy as per the rest of the post meta data? Anything to get me past this issue...

    Thx

  19. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 3 years ago #

    Is the tumblog taxonomy registered on the main site? If it's not then that would prevent it being saved to the main site.

    What you need to return from the filter is the taxonomy field from the term_taxonomy table as a new element in the array per the example.

    I implemented a very similar filter in http://wordpress.org/extend/plugins/genesis-simple-menus/. At the top of the plugin file is an example filter. The only difference is that the filter is genesis_simple_menus_taxonomies where the one in SWT is sitewide_tags_custom_taxonomies.

  20. DoctorDR
    Member
    Posted 3 years ago #

    Yes, the tumblog taxonomy is registered on the main site - it installs as a network activated plugin - http://wordpress.org/extend/plugins/woo-tumblog/ - and then creates the 6 entries in the wp_term_taxonomy table which are the default terms for this taxonomy (video, articles, images, audio, quotes, links).

    The table entry looks like this:

    .       3 	Articles  articles 	0
    	4 	Images 	  images 	0
    	5 	Audio 	  audio 	0
    	6 	Video 	  video 	0
    	7 	Quotes 	  quotes 	0
    	8 	Links 	  links 	0

    I've examined the filter in 'genesis_simple_menus' and there are a couple of 'slight' differences between this and the filter you previously suggested, so I will try this out and see if it makes any difference.

  21. DoctorDR
    Member
    Posted 3 years ago #

    Didn't work.

    I tried the filter like this..

    add_filter( 'sitewide_tags_custom_taxonomies', 'my_swt_custom_tax_filter' );
    function my_swt_custom_tax_filter( $taxonomies ) {
    	$taxonomies[] = 'tumblog';
    	return array_unique( $taxonomies );
    }

    But the main tags blog still does not get updated with the taxonomy, even though the sub-blog is updated correctly.

  22. DoctorDR
    Member
    Posted 3 years ago #

    If the filter code is correct then is there any chance that the sequence in which it fires is the problem? - i.e. is it applying the filter 'after' the duplicate post has been written to the tags blog?

    I'm not entirely sure how to debug a filter (i.e. set triggers to see which path it takes and in what sequence).

  23. DoctorDR
    Member
    Posted 3 years ago #

    Since I have been unable to get a custom taxonomy filter to interact with SWT, I am now trying a post format after switching the settings within my wootumblog sites.

    Ron, you state within your post - http://wpmututorials.com/plugins/sitewide-tags-update/ - that post formats are supported in the SWT plugin, but then you go on to provide the example of a custom post type, which is clearly a different entity.

    The same problem persists now that I'm trying to use post formats - namely that SWT leaves behind these additional postmeta entries when creating the tags blog post. Have you any suggestions on how to pick up the post format and pass it as a single entry in the wp_postmeta table of the tags blog? I am presuming it wouldn't be a good idea to just perform a wholesale write of all the post meta.

    I have tried to perform get_post_format($post_id) within the sitewide_tags_post function in SWT, but I'm getting a NULL value despite $post_id being correct, so I am currently trying to figure out how to get the post format (from within the SWT function) and thereby update the parent tags blog post.

  24. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 3 years ago #

    post formats are a built-in custom taxonomy. The post format taxonomy is post_format.

  25. DoctorDR
    Member
    Posted 3 years ago #

    So what are you advising? Use 'post_format' as the taxonomy name in the above filter?

    i.e.

    add_filter( 'sitewide_tags_custom_taxonomies', 'my_swt_custom_tax_filter' );
    function my_swt_custom_tax_filter( $taxonomies ) {
    	$taxonomies[] = 'post_format';
    	return array_unique( $taxonomies );
    }
  26. DoctorDR
    Member
    Posted 3 years ago #

    I tried the above change in my plugin, but no change to my wp_postmeta table to reflect the post_format elements which were saved at the same time to the sub-blog.

    I even tried amending the taxonomies section within the SWT plugin to read as follows:

    [Code moderated as per the Forum Rules. Please use the pastebin]

  27. DoctorDR
    Member
    Posted 3 years ago #

    If I add in a

    return false;

    at Line 430, just before if( $post->post_status == 'publish' ) {

    Then the post_format meta is successfully updated in the tags blog's wp_postmeta, but I lose the the first four meta entries for the post, namely, '_pingme', '_encloseme', 'permalink', 'blogid'

    That doesn't feel right to me. I thought maybe there was an errant 'shift_array' somewhere, but can't see anything that would cause it - maybe all I've done is replace the main meta items with my new ones?

  28. DoctorDR
    Member
    Posted 3 years ago #

    I can't believe I'm still trying to get this plugin to work as described, but I'm determined to to leave an audit trail for other users so that they can avoid spending the time I already have.

    For the avoidance of doubt, it's easy enough to get the plugin working in its basic configuration - creating a tags blog of the core posts and metadata without further configuration. I had it working in less than 30 minutes, so if that's all you're looking to do, then read no further. The problems start when configuring for custom taxonomies or custom fields (i.e. additional post metadata) and perhaps (especially) when working within a BuddyPress installation.

    I have tried every variation of the 'add_filter' suggestions provided on this post and elsewhere and in my configuration (WP3.1.2 & BP1.2.8), there's not the slightest change in outcome from the SWT plugin. From what I can deduce, the 'wp_get_object_terms' does not function within a BuddyPress installation. That seems a strange conclusion, since it's so core to the workings of the wordpress platform.

    I'm sure it would be useful to know why, at the very least to flag the issue to other BP developers, but there seems little interest in doing so judging my own experiences - but hey, I'd be delighted if somebody could prove me wrong.

    After failing to integrate custom taxonomies with the SWT plugin, I moved over to post formats and specifically the custom fields that I'm working with (video-embed, link-url, quote-copy, quote-author, quote-url, audio, image).

    There is a routine within the **sitewide tags pages plugin** which takes a list of custom fields (entered in the admin settings) and then uses these as keys to read a post and output the keys and values in an array.

    Here's the routine within sitewide-tags.php: http://wordpress.org/extend/plugins/wordpress-mu-sitewide-tags/
    *** line 369 in Version: 0.4.1.1 of sitewide-tags.php ***

    $meta_keys = apply_filters( 'sitewide_tags_meta_keys', get_sitewide_tags_option( 'tags_blog_postmeta', array() ) );
    		$global_meta['DEBUG TEST1'] = $meta_keys;
    		$global_meta['DEBUG TEST2'] = $post_id;
    	if( is_array( $meta_keys ) && !empty( $meta_keys ) ) {
    		foreach( $meta_keys as $key )
    			$global_meta['DEBUG TEST3'] = 'custom loop';
    			$global_meta[$key] = get_post_meta( $post->ID, $key, true );
    	}
    	unset( $meta_keys );

    I have added a small amount of markup to reveal what is happening at each step.

    For my test case, post_id #1121, there is one custom field which sits in the wp_9_postmeta table has one meta_key 'image' with a corresponding meta_value 'http://newsite.com/files/2011/05/alfaP.jpg'

    However the routine returns no value within the function.

    Here's what each of the debug tests shows;

    DEBUG TEST1:

    a:7:{i:0;s:11:"video-embed";i:1;s:9:"image-url";i:2;s:8:"link-url";i:3;s:10:"quote-copy";i:4;s:12:"quote-author";i:5;s:9:"quote-url";i:6;s:9:"audio-url";}

    DEBUG TEST2: 1121
    DEBUG TEST3: Custom Loop

    So the first test (#1) shows that all the custom fields are being returned from the 'get_sitewide_tags_option' on line 1. The second test (#2) confirms it's looking at the correct post_id and the third test (#3) that it reaches the foreach loop and therefore passes the conditional clause.

    I then added a further check to understand what the variable '$key' contains whilst in the foreach loop. In fact, the custom fields are being held within the array but the loop returns NULL when it reaches the 'get_post_meta' command.

    Is this another example where a standard WP command if failing within BP? Seems unlikely but I'll escalate to the BP developer team just in case.

    So, in conclusion if you've been told that the SWT plugin works flawlessly and are about to invest time in making it a part of your own network, then I'd advise you to run a few tests first just to be sure it can meet your needs. There is very little information available and few discussions to learn from, so hopefully this post will provide something to start with.

    Here are some further references I would also recommend for anyone wishing to understand what can be customised:

    http://dev.commons.gc.cuny.edu/2009/07/20/making-sitewide-tags-work/#comment-987

    http://teleogistic.net/2010/08/enabling-popularity-contest-for-wordpress-networkwide-use/

  29. You know ... it occurs to me that BuddyPress, out of the box, does not pick up CPTs and toss 'em in the Activity Stream.
    http://buddypress.trac.wordpress.org/ticket/2559 is a Wont-Fix too, and you have to build your own functions to pull it in.

    So logically this would be a conflict with BP's handling of CPTs, which is munging any other plugin.

    By the way, out of the box, on a fresh build ot WP, it all works just fine, so logically the issue is your setup. Occam's razor and all that :). And since I know you're using BP, my gut feeling would be that it's BP being a bit odd.

    Is this another example where a standard WP command if failing within BP? Seems unlikely but I'll escalate to the BP developer team just in case.

    Actually I'd say that's the MOST likely reason. Head over to buddypress.org and mention it there. It's where the BP gurus hang out.

  30. DoctorDR
    Member
    Posted 3 years ago #

    Thanks, I will dig a little deeper along the path of creating a custom function to duplicate the functionality of WP's commands. It's probably worth me doing that anyway as another test case.

    This 'cannot' be an insurmountable problem - it's only passing a few fields between tables..

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic