The MU forums have moved to WordPress.org

Edit Site Wide Tags to get custom fields (6 posts)

  1. shodezignz
    Member
    Posted 13 years ago #

    HOw do you edit or where in the code of the plugin do you edit it so it will get the custom fields of the posts?

  2. shodezignz
    Member
    Posted 13 years ago #

    Is there anyone that knows where to or how to edit this code to get custom field keys and values?

    function sitewide_tags_options() {

    load_muplugin_textdomain('wpmu-sitewide-tags', MUPLUGINDIR.'/languages');
    if( get_site_option( 'tags_blog_public' ) === null )
    add_site_option( 'tags_blog_public', 1 );

    $tags_blog_enable = get_site_option( 'tags_blog_enable');
    ?><h3><?php _e('Global Tags','wpmu-sitewide-tags') ?></h3>
    <table class="form-table">
    <tr valign="top">
    <th scope="row"><?php _e('Tags Blog','wpmu-sitewide-tags') ?></th>
    <td>
    <label><input name="tags_blog_enabled" type="checkbox" id="tags_blog_enabled" value="1" <?php if( get_site_option( 'tags_blog_enabled', 0 ) == 1 ) { echo "checked='checked'"; } ?>" /> <?php _e("Enabled","wpmu-sitewide-tags"); ?></label>
    <?php
    if( !get_site_option( 'tags_blog_enabled' ) ) {
    echo "</td></tr></table>";
    return;
    }
    ?>
    <p><?php _e( "You can create your post archive in a specific 'tags' blog of your choosing, or you can use the main blog of your site. Each has it's own pros and cons.","wpmu-sitewide-tags"); ?></p>

    1. <input name="tags_blog" type="text" id="tags_blog" style="width: 35%" value="<?php echo attribute_escape( get_site_option( 'tags_blog', 'tags' ) ); ?>" size="45" />
      <?php _e('Blogname of the blog your global tags and posts will live in. Blog will be created.','wpmu-sitewide-tags') ?>
    2. <label><input name="tags_blog_main_blog" type="checkbox" id="tags_blog_main_blog" value="1" <?php if( get_site_option( 'tags_blog_main_blog', 0 ) == 1 ) { echo "checked='checked'"; } ?>" /> <?php _e( "Post to main blog","wpmu-sitewide-tags" ); ?></label>
      <?php _e('Create posts in your main blog. All posts will appear on the front page of your site. Remember to to add a post loop to home.php in the theme directory if it exists.','wpmu-sitewide-tags') ?>

    </td>
    </tr>
    <tr valign="top">
    <th scope="row"><?php _e('Max Posts','wpmu-sitewide-tags') ?></th>
    <td>
    <input name="tags_max_posts" type="text" id="tags_max_posts" style="width: 15%" value="<?php echo intval( get_site_option( 'tags_max_posts', 5000 ) ); ?>" size="5" />

    <?php _e('The maximum number of posts stored in the tags blog.','wpmu-sitewide-tags') ?>
    </td>
    </tr>
    <tr valign="top">
    <th scope="row"><?php _e('Privacy','wpmu-sitewide-tags') ?></th>
    <td>
    <label><input type='radio' name='tags_blog_public' value='1' <?php echo ( get_site_option( 'tags_blog_public' ) == 1 ? 'checked="checked"' : '' ) ?> /> <?php _e('Tags pages can be indexed by search engines.','wpmu-sitewide-tags')?></label>
    <label><input type='radio' name='tags_blog_public' value='0' <?php echo ( get_site_option( 'tags_blog_public' ) == 0 ? 'checked="checked"' : '' ) ?> /> <?php _e('Tags pages will not be indexed by search engines.','wpmu-sitewide-tags')?></label>

    <?php _e('Will your tags pages be visible to Google and other search engines?','wpmu-sitewide-tags') ?>
    </td>
    </tr>
    </table>
    <?php
    }
    add_action('wpmu_options', 'sitewide_tags_options');

    function sitewide_tags_update_options() {
    global $wpdb, $current_site, $current_user;
    if( !$_POST[ 'tags_blog_enabled' ] ) {
    if( get_site_option( 'tags_blog_enabled' ) != $_POST[ 'tags_blog_enabled' ] )
    update_site_option( 'tags_blog_enabled', 0 );
    return;
    }
    update_site_option( 'tags_blog_enabled', 1 );

    if( ( isset( $_POST[ 'tags_blog' ] ) || isset( $_POST[ 'tags_blog_main_blog' ] ) ) && isset( $_POST[ 'tags_blog_public' ] ) ) {
    if( $_POST[ 'tags_blog_main_blog' ] == 1 ) {
    $id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain = '{$current_site->domain}' AND path = '{$current_site->path}'" );
    if( $id ) {
    update_site_option( 'tags_blog_id', $id );
    update_site_option( 'tags_blog_main_blog', 1 );
    } else {
    update_site_option( 'tags_blog_main_blog', 0 );
    }
    } else {
    update_site_option( 'tags_blog_main_blog', 0 );
    $tags_blog = $_POST[ 'tags_blog' ];
    update_site_option( 'tags_blog', $tags_blog );
    if( constant( 'VHOST' ) == 'yes' ) {
    $domain = $tags_blog . '.' . $current_site->domain;
    $path = $current_site->path;
    } else {
    $domain = $current_site->domain;
    $path = trailingslashit( $current_site->path . $tags_blog );
    }
    $tags_blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain = '$domain' AND path = '$path'" );
    if( $tags_blog_id ) {
    update_site_option( 'tags_blog_id', $tags_blog_id );
    } else {
    $wpdb->hide_errors();
    $id = wpmu_create_blog( $domain, $path, __( 'Global Posts','wpmu-sitewide-tags' ), $current_user->id , array( "public" => $_POST[ 'tags_blog_public' ] ), $current_site->id);
    update_site_option( 'tags_blog_id', $id );
    $wpdb->show_errors();
    }
    }
    $tags_blog_public = (int)$_POST[ 'tags_blog_public' ];
    update_site_option( 'tags_blog_public', $tags_blog_public );
    update_blog_option( $tags_blog_id, 'blog_public', $tags_blog_public );
    update_blog_status( $tags_blog_id, 'public', $tags_blog_public);
    }

    if( isset( $_POST[ 'tags_max_posts' ] ) )
    update_site_option( 'tags_max_posts', (int)$_POST[ 'tags_max_posts' ] );
    }
    add_action( 'update_wpmu_options', 'sitewide_tags_update_options' );

    function sitewide_tags_post( $post_id, $post ) {
    global $wpdb;

    if( !get_site_option( 'tags_blog_enabled' ) )
    return;

    // wp_insert_category()
    include_once(ABSPATH . 'wp-admin/includes/admin.php');

    $tags_blog_id = get_site_option( 'tags_blog_id' );
    if( !$tags_blog_id )
    return;

    if ( $wpdb->blogid == $tags_blog_id || $post->post_status == 'inherit' || $post->post_type != 'post' || $post->post_status == 'revision' )
    return;

    $post_blog_id = $wpdb->blogid;
    /*
    * this will not handle a switch from public to private blog and delete posts in tags-blog
    */
    if ( get_blog_status($post_blog_id, "public") != 1 )
    return;

    $post->post_category = wp_get_post_categories( $post_id );
    foreach( $post->post_category as $c ) {
    $cat = get_category( $c );
    $cats[] = $cat->name;
    }

    $post->tags_input = implode( ', ', wp_get_post_tags( $post_id, array('fields' => 'names') ) );
    $post->guid = $post_blog_id . '.' . $post_id;

    $permalink = get_permalink( $post_id );

    switch_to_blog( $tags_blog_id );
    if( is_array( $cats ) && !empty( $cats ) ) {
    foreach( $cats as $t => $d ) {
    wp_insert_category( array('cat_name' => $d, 'category_parent' => '') );
    }
    }

    $global_post = $wpdb->get_row( "SELECT * FROM {$wpdb->posts} WHERE guid = '{$post->guid}'" );
    if( $post->post_status != 'publish' && is_object( $global_post ) ) {
    wp_delete_post( $global_post->ID );
    } else {
    if( $global_post->ID != '' ) {
    $post->ID = $global_post->ID; // editing an old post
    /* using this kind of update not simple add: fixing permalink-problems */
    delete_post_meta( $global_post->ID, "permalink");
    } else {
    unset( $post->ID ); // new post
    }

    $post->ping_status = 'closed';
    $post->comment_status = 'closed';

    $p = wp_insert_post( $post );
    add_post_meta( $p, "permalink", $permalink );
    }
    restore_current_blog();
    }
    add_action('save_post', 'sitewide_tags_post', 10, 2);

    function sitewide_tags_post_delete( $post_id ) {
    /*
    * what should we do if a post will be deleted and the tags blog feature is disabled?
    * need an check if we have a post on the tags blog and if so - delete this
    */
    global $wpdb;
    $tags_blog_id = get_site_option( 'tags_blog_id' );
    if( null === $tags_blog_id )
    return;

    if( $wpdb->blogid == $tags_blog_id )
    return;

    $post_blog_id = $wpdb->blogid;
    switch_to_blog( $tags_blog_id );
    $global_post_id = $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE guid = '{$post_blog_id}.{$post_id}'" );
    if( null !== $global_post_id )
    wp_delete_post( $global_post_id );

    restore_current_blog();
    }
    add_action('delete_post', 'sitewide_tags_post_delete');

    /**
    * remove all posts from a given blog ($blog_id != 0)
    * - used if a blog is deleted or marked as deactivat, spam, archive, mature
    * - also runs if a blog is switched to a none public blog (called by
    * sitewide_tags_public_blog_update), more details on sitewide_tags_public_blog_update
    * removes some posts if the limit is reached ($blog_id == 0)
    * - triggered by other actions but without an given blog_id
    * - number of posts to delete in $max_to_del
    *
    * @param $blog_id
    */
    function sitewide_tags_remove_posts($blog_id = 0) {
    global $wpdb;
    $tags_blog_id = get_site_option( 'tags_blog_id' );
    $max_to_del = 10;

    if( !$tags_blog_id )
    return;

    /* actions on the tags blog */
    if ( ($blog_id == 0) && ($wpdb->blogid == $tags_blog_id) )
    return;
    if ( $tags_blog_id == $blog_id )
    return;

    switch_to_blog( $tags_blog_id );

    if ( $blog_id != 0 ) {
    $posts = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE guid LIKE '".$blog_id.".%'");
    if( is_array( $posts ) && !empty( $posts ) ) {
    foreach( $posts as $p_id ) {
    wp_delete_post( $p_id );
    }
    }
    } else {
    /* delete all posts - not pages - over the max limit */
    if( mt_rand( 0, 10 ) ) {
    $posts = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE post_status='publish' AND post_type='post' ORDER BY ID DESC limit " . get_site_option( 'tags_max_posts', 5000 ) . ", " . $max_to_del );
    if( is_array( $posts ) && !empty( $posts ) ) {
    foreach( $posts as $p_id ) {
    wp_delete_post( $p_id );
    }
    }
    }
    }
    restore_current_blog();
    }
    /* complete blog actions ($blog_id != 0) */
    add_action('delete_blog', 'sitewide_tags_remove_posts', 10, 1);
    add_action('archive_blog', 'sitewide_tags_remove_posts', 10, 1);
    add_action('deactivate_blog', 'sitewide_tags_remove_posts', 10, 1);
    add_action('make_spam_blog', 'sitewide_tags_remove_posts', 10, 1);
    add_action('mature_blog', 'sitewide_tags_remove_posts', 10, 1);
    /* single post actions ($blog_id == 0) */
    add_action("transition_post_status", 'sitewide_tags_remove_posts');

    /**
    * called as an action if the public state for a blog is switched
    * - if a blog becomes not public - all posts in the tags blog will be removed
    * - bug on 1.5.1: update_option_blog_public is only triggered if the public state
    * is changed from the backend - from edit blog as siteadmin the action isn't
    * running and the state in the blogs backend isn't changed
    *
    * @param int $old - old public state
    * @param int $new - new state, public == 1, not public == 0
    */
    function sitewide_tags_public_blog_update($old, $new) {
    global $wpdb;
    $tags_blog_id = get_site_option( 'tags_blog_id' );

    if( !$tags_blog_id )
    return;

    /* the tags blog */
    if ( $tags_blog_id == $wpdb->blogid )
    return;

    if ($new == 0 ) {
    sitewide_tags_remove_posts($wpdb->blogid);
    }
    }
    add_action('update_option_blog_public', 'sitewide_tags_public_blog_update', 10, 2);

    function sitewide_tags_post_link( $link, $post ) {
    global $wpdb;
    $tags_blog_id = get_site_option( 'tags_blog_id' );
    if( !$tags_blog_id )
    return $link;

    if( $wpdb->blogid == $tags_blog_id ) {
    $url = get_post_meta( $post->ID, "permalink", true );
    if( $url )
    return $url;
    }
    return $link;
    }
    add_filter('post_link', 'sitewide_tags_post_link', 10, 2);
    ?>

  3. shodezignz
    Member
    Posted 13 years ago #

    The answer was easier than i first thought and Donncha did not help at all even with two emails directly to him.

    All you have to do is this
    ** is a line already in the code
    add this after ** line
    **158 $permalink = get_permalink( $post_id );
    $articlevalue = get_post_meta($post_id, 'articleimg', true);
    $thumbvalue = get_post_meta($post_id, 'thumbnailimg', true);
    $featuredvalue = get_post_meta($post_id, 'featuredtext', true);

    and
    **186 add_post_meta( $p, "permalink", $permalink );
    add_post_meta( $p, 'articleimg', $articlevalue);
    add_post_meta( $p, 'thumbnailimg', $thumbvalue);
    add_post_meta( $p, 'featuredtext', $featuredvalue);
    this will make it so feature content gallery will work on the main blog

  4. dsader
    Member
    Posted 13 years ago #

    shodezignz, posting what you figured out ... is appropriate.
    Adding a "nana nana boo boo" to anyone, but especially Donncha, is terribly NOT appropriate! IMHO.

  5. kunal17
    Member
    Posted 13 years ago #

    Thanks for posting the customizations. I also am trying to build a featured content gallery for my WPMU+Buddypress setup front page that can pull posts I want from certain subblogs.

    I have a few questions:
    - Which is the best (easiest) featured content plugin to use with WPMU?
    - Featured content gallery plugins uses mootools I think. Does this conflict with the default jquery library that comes with wordpress?
    - I already have sitewide tags plugins aggregating posts in my setup. However, all this time I have had it on a tags blog because I was using the main blog for site news. Is there a way I can use your customized sitewide plugin to look at the tags blog but show the featured section in the main blog frontpage?
    - Is there any way I can now transfer the plugin to start using the main blog so that I can use your solution? Would this delete all the posts it has aggregated so far?

    Sorry if this is a lot of questions. I have tried to do my research across the forums forums for quite some time but have not been able to find a good solution for what I am trying to do which is to create a featured content slider on the front page which pulls in certain specified posts from specific sub blogs.

    Thanks for any help or helpful links you experts can provide!

    Regards,
    Kunal

  6. shodezignz
    Member
    Posted 12 years ago #

    Sorry it took me so long to reply but i have not looked on here since my last post awhile ago.
    1. I do not know which is the easiest plugin. I am using the Featured Content Gallery.
    2. I am still new to all of this but from what i can tell it does not conflict with anything
    3. I think so because even tho you set up a tags blog it should be pulling in the stuff from your main blog too. It is all about categories.
    4. I have no idea about that. I think there is a way to transfer posts but i do not know anything about that.

    The way i worked everything out was in each sub-blog i made a category Featured and that is what shows up on the main blog page and also in the Featured Content Gallery becasue you can set it to display a certain category. I hope this is helpful and good luck. once again sorry for the late reply Kunal

    Sho

About this Topic

  • Started 13 years ago by shodezignz
  • Latest reply from shodezignz