• Resolved bencico

    (@bencico)


    Hi,
    I have a custom post type set up called ebooks. I use BeaverBuilder to have a post grid shown on a page, with pagination. This page is called ebooks, and it has the page Resources set as parent. The code for the pagination is the following:

    
    public static function pagination( $query ) {
    		$total_pages         = $query->max_num_pages;
    		$permalink_structure = get_option( 'permalink_structure' );
    		$paged               = FLBuilderLoop::get_paged();
    		$base                = html_entity_decode( get_pagenum_link() );
    		$add_args            = false;
    
    		if ( $total_pages > 1 ) {
    
    			if ( ! $current_page = $paged ) { // @codingStandardsIgnoreLine
    				$current_page = 1;
    			}
    
    			$base   = FLBuilderLoop::build_base_url( $permalink_structure, $base );
    			$format = FLBuilderLoop::paged_format( $permalink_structure, $base );
    			// Flag if it's a first posts module in an archive page.
    			// Fix pagination issues in archive page since it's using the main WP query for pagination.
    			if ( $query->is_archive && 1 === FLBuilderLoop::$loop_counter ) {
    				if ( isset( $query->query['settings']->data_source ) && 'custom_query' === $query->query['settings']->data_source ) {
    					$add_args = array(
    						'flpaging' => 1,
    					);
    				}
    			}
    			// phpcs:ignore
    			echo paginate_links(
    				array(
    					'base'      => $base . '%_%',
    					'format'    => $format,
    					'prev_text' => '<span class="btn btn-secondary btn-sm">' . __( 'Newer posts', 'memoq_bb' ) . '</span>',
    					'next_text' => '<span class="btn btn-secondary btn-sm">' . __( 'Older posts', 'memoq_bb' ) . '</span>',
    					'current'   => $current_page,
    					'total'     => $total_pages,
    					'type'      => 'plain',
    					'add_args'  => $add_args,
    				)
    			);
    		}
    

    The link on the older posts button is https://mysite.com/resources/ebooks/page/2 .

    Post type slug: ebook
    Has archive: false
    Custom rewrite slug: resources/ebooks

    When I have the Rewrite option set to true, the pagination button link goes to 404, when it is set to false, it works fine. Both times the link on the button is the same.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter bencico

    (@bencico)

    Oh, and this is on my local version of the site. On staging and on the live site, the problem is a bit different: when I set Rewrite to true, I have the https://mysite.com/resources/ebooks/page/2 link on the button, and it goes to 404, and when I set Rewrite to false, the link becomes https://mysite.com/resources/ebooks/ (so the link is the same as the link of the page itself), but when I add the /page/2 by hand, it works…

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Really hard for me to say what’s going on here as there are many details in play.

    1) Some sort of class/static setup that may or may not be tied into WordPress hooks.
    2) A lot of setup that looks to rely on some code from provides this FLBuilderLoop code
    3) a post type that also has a page matching the same overall slug.
    4) a post type rewrite value that at least sometimes appears to work, but really is not the best type of value to put in that field.
    5) Pagination tends to be a pain with post types anyway, at least when it comes to custom WP_Query invocations.
    6) It’s not easy to say which query the pagination is being acted on here. Whether it be the one for the “ebooks” PAGE or whatever query is being made for the post type itself.

    Realistically, as long as your ebook post type and any taxonomies are able to have new posts created, edited, published, etc, then much of what CPTUI handles is done. Our focus is getting them registered based on the parameters provided. However, we don’t have any direct influence at all on how they’re used after the fact.

    I’m willing to try and offer what ideas I have still, but there’s a lot to sort out as I’ve mentioned above.

    Thread Starter bencico

    (@bencico)

    Hi Michael,
    Thank you for the quick response.
    I would be very happy to show you the site, if you would be able to take a look at it.

    • This reply was modified 5 years, 3 months ago by bencico.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I’m willing to do glances over, but I’m not going to be able to do any sort of deep diving, as it’s not technically an issue with our plugin, but just headaches and pains from trying to get pagination working as a whole for a custom posts query.

    Thread Starter bencico

    (@bencico)

    Thank you very much, I’ve contacted you on the Making WordPress slack workspace.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Could you actually reach out via https://pluginize.com/contact/ so that we can get a ticket in our premium support area created?

    We can discuss some more details there.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Pagination link returns 404 with custom rewrite’ is closed to new replies.