0

I had the problem that tags of private posts didn't show up in a widget tag-cloud even if the user is logged in. The reason seems to be the value of "post_status" in the function _update_post_term_count in wp-include/taxonomy.php. At least when I change this value to "private" private tags are displayd.

My question is: how can I change this value without editing taxonomy.php, thus the core? This is the altered function (changes in

**...**

):

function _update_post_term_count( $terms, $taxonomy ) {
    global $wpdb;

    $object_types = (array) $taxonomy->object_type;

    foreach ( $object_types as &$object_type )
        list( $object_type ) = explode( ':', $object_type );

    $object_types = array_unique( $object_types );

    if ( false !== ( $check_attachments = array_search( 'attachment', $object_types ) ) ) {
        unset( $object_types[ $check_attachments ] );
        $check_attachments = true;
    }

    if ( $object_types )
        $object_types = esc_sql( array_filter( $object_types, 'post_type_exists' ) );

    foreach ( (array) $terms as $term ) {
        $count = 0;

        // Attachments can be 'inherit' status, we need to base count off the parent's status if so
        if ( $check_attachments )
            $count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts p1 WHERE p1.ID = $wpdb->term_relationships.object_id AND ( post_status = '**private**' OR ( post_status = 'inherit' AND post_parent > 0 AND ( SELECT post_status FROM $wpdb->posts WHERE ID = p1.post_parent ) = '**private**' ) ) AND post_type = 'attachment' AND term_taxonomy_id = %d", $term ) );

        if ( $object_types )
            $count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = '**private**' AND post_type IN ('" . implode("', '", $object_types ) . "') AND term_taxonomy_id = %d", $term ) );

        do_action( 'edit_term_taxonomy', $term, $taxonomy );
        $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
        do_action( 'edited_term_taxonomy', $term, $taxonomy );
    }
}
6
  • That is not what the Core code looks like so I assume this is your hacked version. Please explain what you are trying to accomlish.
    – s_ha_dum
    Commented Apr 20, 2014 at 20:05
  • Yes, this is the hack, I changed "publish" to "private". But I don't want it in the core.
    – raccol
    Commented Apr 20, 2014 at 20:10
  • But why? What is the ultimate goal? There are no filters to alter that query, so you can't alter it without hacking Core. You might be able to use one of the actions but I don't know what you are trying to accomplish.
    – s_ha_dum
    Commented Apr 20, 2014 at 20:18
  • The reason is, that I want to show the tags of a private post. They usually are not displayd and I think the reason is this function.
    – raccol
    Commented Apr 20, 2014 at 20:51
  • I have to clarify: The tags are usually not displayed in a tag-cloud.
    – raccol
    Commented Apr 21, 2014 at 11:23

1 Answer 1

0

There is no way to make the tag of a private post showed up by default, at least for now. I was hoping wp_tag_cloud be the answer but it isn't. One alternative aside from hacking the core code is to create your own widget through plugin. But then I found a plugin that does exactly what I want.

https://wordpress.org/plugins/ultimate-tag-cloud-widget/screenshots/

hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.