Skip to:
Content
Pages
Categories
Search
Top
Bottom

Selected doc displaying wrong info

  • so i’ve added the parents and children links as tabs such as when you click on a document, the name of it’s parent doc appears as a tab to the left and the names of it’s children appear as tabs to the right. The only problem is that is that the “current” doc isn’t loading the right information.

    The “current” doc is displaying the information for the doc who’s tab is placed last on the right. So basically a doc with children is displaying the information for its last child.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Profile photo of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    How did you add the new tab?

    for the children, i made a duplicate of you “show_children()” in the addon_hierarchy.php file and modified the end of it to look like so:

    $html = '';
    if ( !empty( $child_data ) ) {
    
    foreach( $child_data as $child ) {
    $children_html = '<li><a href="' . $child . '">' . $child . '</a></li>';
    echo $children_html;
    }

    then i did add_action to it in the _construct();
    and called it in integration-groups.php

    <li class="current"><a href="root_domain . '/' . $groups_slug ?>/slug ?>/bp_docs->slug ?>/post_name ?>"></a></li>

    it didnt show, but right under where you add the tab for the current_doc i call

    do_action( ‘bp_docs_children_tab’ )

    …i dont know what ‘backticks’ are

    Profile photo of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    What’s the URL of the page that is showing the wrong doc data?

    the URL is /docs/ the title of the document who’s tab is currently selected.

    but it is displaying the info of it’s child document.

    i thought that maybe it was calling URL of the child, but its not….

    Profile photo of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    I guess I’m not really sure what’s happening, based on what you’ve said here. Do you have a link or something? Have you done all of this by modifying the plugin itself, or have you done it through bp-custom.php or another plugin? Can you send me your modifications?

    i did it by modifying the plugin itself. here are the snippets from the two files that i modified

    addon-hierarchy.php

    ` function __construct() {
    // Make sure that the bp_docs post type supports our post taxonomies
    add_filter( ‘bp_docs_post_type_args’, array( $this, ‘register_with_post_type’ ) );

    // Hook into post saves to save any taxonomy terms.
    add_action( ‘bp_docs_doc_saved’, array( $this, ‘save_post’ ) );

    // Display a doc’s parent on its single doc page
    add_action( ‘bp_docs_single_doc_meta’, array( $this, ‘show_parent’ ) );

    add_action( ‘bp_docs_parent_tab’, array( $this, ‘show_parent’ ) );

    // Display a doc’s children on its single doc page
    add_action( ‘bp_docs_single_doc_meta’, array( $this, ‘show_children’ ) );

    add_action( ‘bp_docs_children_tab’, array( $this, ‘show_children_tab’ ) );
    }
    function show_children_tab() {
    global $bp;

    // Get the child posts
    $child_posts_args = array(
    ‘post_type’ => $bp->bp_docs->post_type_name,
    ‘post_parent’ => get_the_ID()
    );

    $child_posts = new WP_Query( $child_posts_args );

    // Assemble the link data out of the query
    $child_data = array();
    if ( $child_posts->have_posts() ) {
    while ( $child_posts->have_posts() ) {
    $child_posts->the_post();

    $child_id = get_the_ID();
    $child_data[$child_id] = array(
    ‘post_name’ => get_the_title(),
    ‘post_link’ => bp_docs_get_doc_link( $child_id )
    );
    }
    }

    $child_data = apply_filters( ‘bp_docs_hierarchy_child_data’, $child_data );

    // Create the HTML
    $html = ”;
    if ( !empty( $child_data ) ) {

    foreach( $child_data as $child ) {
    $children_html = ‘

  • ‘ . $child . ‘
  • ‘;
    echo $children_html;
    }

    }

    } `

    integration-groups.php

    `

  • <a href="root_domain . ‘/’ . $groups_slug ?>/slug ?>/bp_docs->slug ?>/post_name ?>”>
  • `

Profile photo of Boone Gorges
Boone Gorges
Keymaster

@boonebgorges

It looks like this is being caused by a WP bug, which is causing the $post global to get tainted by your subquery (in show_children_tab()). I’m not sure how to fix it. I’ll think about it.

Profile photo of Boone Gorges
Boone Gorges
Keymaster

@boonebgorges

OK, here’s a workaround, until the WP bug is fixed. Instead of using the WP loop functions in show_children_tab(), just do a foreach loop, like this:
`function show_children_tab() {
global $bp;

// Get the child posts
$child_posts_args = array(
‘post_type’ => $bp->bp_docs->post_type_name,
‘post_parent’ => get_the_ID()
);

$child_posts = new WP_Query( $child_posts_args );

// Assemble the link data out of the query
$child_data = array();

foreach( (array)$child_posts->posts as $child_post ) {
$child_id = $child_post->ID;
$child_data[$child_id] = array(
‘post_name’ => $child_post->post_title,
‘post_link’ => bp_docs_get_doc_link( $child_id )
);
}

$child_data = apply_filters( ‘bp_docs_hierarchy_child_data’, $child_data );

// Create the HTML
$html = ”;
if ( !empty( $child_data ) ) {

foreach( $child_data as $child ) {
$children_html = ‘

  • ‘ . $child . ‘
  • ‘;
    echo $children_html;
    }

    }

    }`

    That should solve the problem.

    that worked! thanks alot!

    Viewing 10 replies - 1 through 10 (of 10 total)
    • The topic ‘Selected doc displaying wrong info’ is closed to new replies.