Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Posts on Profile

  • Hi- like the Posts on Profile plugin, but for wordpress 3.0 it is not picking up posts classified using either a custom post type or filed in a particular taxonomy. I think this section of code in the plugin is the one that needs altering:
    `function bp_postsonprofile_setup_nav() {
    global $bp, $wpdb;
    $user_id = bp_displayed_user_id() ? bp_displayed_user_id() : bp_loggedin_user_id();
    $where = $wpdb->prepare(‘WHERE post_author = %d AND post_type = %s AND post_status=%s’, $user_id, ‘post’, ‘publish’);
    $post_count = $wpdb->get_var( “SELECT COUNT(*) FROM $wpdb->posts $where” );
    $post_count = $post_count ? $post_count : 0;
    $postsonprofile_link = $bp->loggedin_user->domain . $bp->postsonprofile->slug . ‘/’;
    `
    What I’d like to do is be able to use this plugin to call a member’s custom posts. For example – let’s say I created a new post type called ‘movies’. This post type contains taxonomies such as ‘genres’, ‘actors’ etc. These taxonomies contain terms such as ‘horror’. I want to have a tab on the BP Profile page which say ‘Movies’ (not ‘posts’) and it shows an archive of all posts submitted by this user using the movies post type. I think this should be easy for an experienced BP programmer :) Something in the above code which uses post_type=’movies’. Something like this perhaps:
    `
    <?php global $wp_query;
    query_posts( array(
    ‘post_type’ => ‘movies’ ,
    “genre” => “horror”, “comedy” etc
    ‘showposts’ => 10 )
    );
    ?>

    Any suggestions would be greatly appreciated. Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Above should read:

    global $wp_query;
    query_posts( array(
    ‘post_type’ => ‘movies’ ,
    “genre” => “horror”, “comedy”,
    ‘showposts’ => 10)
    );

    This definately works in a WP 3.0 template. Thanks

    Anyone with an idea?

    Still no reply from anyone – as with another of my posts. :(


    Shrikant Joshi
    Member

    @shrikantjoshi

    Ah, 8 months and no reply. I figured, it’d be a long time before anyone answered to this thread, so I got down to get my hands dirty.

    Now, I’m not a developer at all, so most of my hacks are just that – hacks. Well, anything will do as long as it gets the code working, I figured. If anyone wants to modify the hack into something more elegant, be my guest!! :)

    Two changes:

    1. Change line 45 in `wp-content/plugins/bp-posts-on-profile/includes/bp-postsonprofile-core.php` from:
    `$where = $wpdb->prepare(‘WHERE post_author = %d AND post_type=%s AND post_status=%s’, $user_id, ‘post’, ‘publish’);`
    to:
    `$where = $wpdb->prepare(‘WHERE post_author = %d AND (post_type = %s OR post_type=%s) AND post_status=%s’, $user_id, ‘post’, ‘your-custom-post’, ‘publish’);`

    where `your-custom-post` is the name of your custom post type. If you have more than one custom post, you’ll have to make changes to the part where it says: ‘(post_type = %s OR post_type=%s)’ to include all of them. (Like I said, inelegant, but mostly effective)

    2. Change line no.25 in `/wp-content/plugins/bp-posts-on-profile/includes/templates/postsonprofile/screen-one.php` from:
    `query_posts(‘&author=’. bp_displayed_user_id() .’&paged=’. bp_pop_cur_page());`
    to:
    `query_posts(‘post_type=any’ .’&author=’. bp_displayed_user_id() .’&paged=’. bp_pop_cur_page()); `

    If you’re wondering, “Can it really be so simple?” The answer is, NO. There’s a tiny little problem – for some reason, it breaks the sidebar and pushes it below the content. I’m still racking my brains to figure out which part of the code is responsible.

    As I’ve mentioned I’m NOT a developer – I’ve taken to learning PHP & WordPress from the ground up. If anyone else can chip in it’d be a great help! Thanks & hope it helps you as well. :)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Posts on Profile’ is closed to new replies.
Skip to toolbar