Skip to:

Get post in new member tab; url_to_postid() not working

  • Nimenenea


    Hi, I am using the code below found on this support page to have a new tab on the Member page. Inside it I want to display a certain post (I have the permalink) and to do that I need to transform the permalink into the post ID. In the WordPress Codex url_to_postid() does just that. But it doesn’t work on the Member page. It works like a charm everywhere else.
    Surely I am doing something wrong.

    //Displaying a new tab
    function my_test_setup_nav() {
    global $bp;
    bp_core_new_nav_item( array( ‘name’ => __( ‘test’ ), ‘slug’ => ‘test’, ‘parent_url’ => $bp->loggedin_user->domain . $bp->slug . ‘/’, ‘parent_slug’ => $bp->slug, ‘screen_function’ => ‘my_profile_page_function_to_show_screen’, ‘position’ => 80 ) );
    bp_core_new_subnav_item( array( ‘name’ => __( ‘Home’ ), ‘slug’ => ‘test_sub’, ‘parent_url’ => $bp->loggedin_user->domain . $bp->slug . ‘/’, ‘parent_slug’ => $bp->slug, ‘parent_slug’ => $bp->slug, ‘screen_function’ => ‘my_profile_page_function_to_show_screen’, ‘position’ => 20, ‘item_css_id’ => ‘test_activity’ ) );
    function my_profile_page_function_to_show_screen() {
    //add title and content here – last is to call the members plugin.php template
    add_action( ‘bp_template_title’, ‘my_profile_page_function_to_show_screen_title’ );
    add_action( ‘bp_template_content’, ‘my_profile_page_function_to_show_screen_content’ );
    bp_core_load_template( apply_filters( ‘bp_core_template_plugin’, ‘members/single/plugins’ ) );
    function my_profile_page_function_to_show_screen_title() {
    echo ‘something’;
    function my_profile_page_function_to_show_screen_content() {

    //get the permalink
    $url = get_bloginfo( url ).’/’.bp_get_displayed_user_username().’/post-name/’ ;

    //transform the permalink in ID and display post
    $my_postid = url_to_postid( $url );
    $content_post = get_post($my_postid);
    $content = $content_post->post_content;
    $content = apply_filters(‘the_content’, $content);
    $content = str_replace(‘]]>’, ‘]]>’, $content);
    echo $content;
    add_action( ‘bp_setup_nav’, ‘my_test_setup_nav’ );`

    Everything works, I’ve tested it, the problem is with the url_to_postid() function. I am not using custom posts.

    Thank you.

  • The topic ‘Get post in new member tab; url_to_postid() not working’ is closed to new replies.
Skip to toolbar