Skip Navigation

[Resolved] Views gives error trying to paginate results on BuddyPress profile

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to render a View in a BuddyPress PHP template file but when I use pagination I am shown a JavaScript error.

Solution: Use the render_view API to render a View in a PHP template.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-api/#render_view

This support ticket is created 6 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 4.98 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 6 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#971578
Screenshot from 2018-07-30 09-18-12.png

I am trying to:
Display all Obra custom post type from an user in his BuddyPress profile.

Link to a page where the issue can be seen:
hidden link

I expected to see:
It shows the first page and when it tries to get the next, it gives a javascript error for not finding where it needs to put the new page.

wpv-pagination-embedded.js?ver=2.6.3:2326

Uncaught TypeError: Cannot read property 'replace' of undefined
at Object.infinite (wpv-pagination-embedded.js?ver=2.6.3:2326)
at WPViews.ViewPagination.self.pagination_slide (wpv-pagination-embedded.js?ver=2.6.3:2078)
at WPViews.ViewPagination.self.prepare_slide (wpv-pagination-embedded.js?ver=2.6.3:2020)
at WPViews.ViewPagination.self.trigger_pagination (wpv-pagination-embedded.js?ver=2.6.3:1945)
at HTMLDivElement.<anonymous> (wpv-pagination-embedded.js?ver=2.6.3:3086)
at Function.each (jquery.js?ver=1.12.4:2)
at a.fn.init.each (jquery.js?ver=1.12.4:2)
at wpv-pagination-embedded.js?ver=2.6.3:3078
at underscore.min.js?ver=1.8.3:5
at c (underscore.min.js?ver=1.8.3:5)

Instead, I got:
It waits loading. Look at the screenshot or access the profile page of an user and scroll down to see the problem.

#1011917

Hi, can you tell me more about this site?
- How is this View of Obras added to the BuddyPress Profile? Please include any shortcodes or custom PHP code used.
- Please temporarily activate a default theme like Twenty Seventeen, then deactivate all plugins except Types, Views, and BuddyPress. Test again. Is the problem resolved?

If the problem was resolved, reactivate your theme and plugins one by one until the problem returns.

#1078795
Screenshot from 2018-08-09 19-33-18.png

Hi Christian,

This is how i am creating a tab in the buddypress profile and showing the view:

function profile_tab_obras() { 		
	global $bp;

	bp_core_new_nav_item( array( 
	    'name' => 'Obras', 
	    'slug' => 'obras', 
	    'screen_function' => 'obras'.'_screen', 
	    'position' => 40,
	    'parent_url'      => bp_displayed_user_domain()  . '/'.'obras'.'/',
		'parent_slug'     => $bp->profile->slug,
		'default_subnav_slug' => 'obras'
	));
}
add_action( 'bp_setup_nav', 'profile_tab_'.'obras' );
 
 
function obras_screen() {
    //add title and content here - last is to call the members plugin.php template
    add_action( 'bp_template_title', 'obras_title' );
    add_action( 'bp_template_content', 'obras'.'_content' );
    bp_core_load_template( 'buddypress/members/single/plugins' );
}

function obras_title() {
    echo 'Obras';
}

function obras_content() { 
	//echo do_shortcode("[wpv-view name='".'obras'."-mine']");
	$user_id = bp_displayed_user_id();
    $curr_id = get_current_user_id();
    if ($user_id == $curr_id) {
        echo '<div class="" id="title_btn">
                <a class="btn btn-default" href="/obras/cadastrar-obra/" title="">
                    <i class="vc_btn3-icon fa fa-plus"></i> '.__('Cadastrar Obra').'
                </a>
            </div>';       
    }
	echo do_shortcode("[wpv-view name='itens-mine-profile' author='$user_id']");
}

Made what you said changing the theme and disabling plugins, but it won't work. There is some conflict with buddypress, because when i remove the infinite scrolling and use ajax paging, on clicking to change the page, gives another javascript error, but on buddypress(!?)

#1080651

Okay thanks. Per our support policy, I'm not able to troubleshoot custom theme files. However, I am able to give you a working example to help you figure out why your custom code is not working as expected. Let me show you an example BuddyPress profile template. This custom template file index.php is saved in a custom theme in the directory /wp-content/my-theme/buddypress/members/single/. Notice that I am using the render_view API instead of do_shortcode, and passing the required shortcode arguments into the $args array. This is the preferred method of rendering a View in PHP.

<?php get_header(); ?>

	<div id="content">
		<div class="padder">

		<?php do_action( 'bp_before_blog_page' ); ?>

		<div class="page" id="blog-page" role="main">

			<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

				<h2 class="pagetitle"><?php the_title(); ?></h2>

				<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

					<div class="entry">

						<?php the_content( __( '<p class="serif">Read the rest of this page &rarr;</p>', 'buddypress' ) ); ?>

						<?php wp_link_pages( array( 'before' => '<div class="page-link"><p>' . __( 'Pages: ', 'buddypress' ), 'after' => '</p></div>', 'next_or_number' => 'number' ) ); ?>
						<?php edit_post_link( __( 'Edit this page.', 'buddypress' ), '<p class="edit-link">', '</p>'); ?>

					</div>

					<?php
echo render_view(array( 'name' => 'itens-mine-profile', 'author' => '1'));
					?>

				</div>

			<?php comments_template(); ?>

			<?php endwhile; endif; ?>

		</div><!-- .page -->

		<?php do_action( 'bp_after_blog_page' ); ?>

		</div><!-- .padder -->
	</div><!-- #content -->

	<?php get_sidebar(); ?>

<?php get_footer(); ?>

Here is the documentation for the render_view API:
https://toolset.com/documentation/programmer-reference/views-api/#render_view