• [redacted] the staging site https://www.marcolapegna.com/staging/

    [redacted]

    As you can see with the blog on main page I am getting pagination with the main theme. The second blog under PEI corner is built using a child theme and I am not getting pagination even though I have 6 posts.

    This is the function I have for pagination of the custom post, it’s almost exactly the same one from the parent theme.

    if (!function_exists('unblock_peipaging_nav')) :
    
    	function unblock_peipaging_nav()
    	{
    		$peiCorner = new WP_Query(array(
    			"posts_per_page" => 5,
    			"post_type" => "event"
    			));
    		the_posts_pagination(array(
    			"total" => $peiCorner-> max_num_pages,
    			'prev_text' => is_rtl() ? '<i class="bi bi-caret-right-fill"></i>' : '<i class="bi bi-caret-left-fill"></i>',
    			'next_text' =>  is_rtl() ? '<i class="bi bi-caret-left-fill"></i>' : '<i class="bi bi-caret-right-fill"></i>',
    			'before_page_number' => ''
    		));
    	}
    endif;

    You can get access to both the parent and child theme files here if you need to look deeper. https://github.com/xVicissitudex/WordPress-Themes

    I can’t for the life of me figure out why it’s not working I pretty much copied and pasted the code over.

    • This topic was modified 2 years, 11 months ago by bcworkz. Reason: access credentials redacted

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    @vecissitude – please never provide any sort of login credentials for any kind of site in these forums. I’m reasonably sure the user credentials you provided had no capability of doing anything risky on your staging site. And perhaps you wouldn’t have cared much if someone were able to somehow corrupt your staging site. The specific risk here is not important. We don’t want to establish a precedent here where people freely share credentials. Sooner or later a less sophisticated user will share admin credentials to their production site and bad things could happen. We draw a hard line at any kind of sharing of login credentials for everyone’s safety. We appreciate your understanding.

    I think I know what your issue is without even seeing your site. Nearly all WP pagination functions assume they are paginating the main query. When you paginate a secondary query, these functions are working off the wrong set of query data. You cannot use these functions to paginate secondary queries. The one exception is paginate_links(). Because you pass all the information it needs you can paginate any query with it.

    You’ll see examples using paginate_links() where the requested page is taken from the “paged” query var. While this often will work, it does so unreliably. The “paged” query var belongs to the main query, not your secondary query. It may not be an appropriate value for your query. For example, page post types do not paginate and “paged” is always blanked. I recommend establishing your own custom query var to pass to paginate_links().

    Thread Starter vecissitude

    (@vecissitude)

    Thanks that does seem to have made things better.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Adding pagination to 2nd custom post types’ is closed to new replies.