I have custom query with custom pagination with which I'd like to use pretty urls, like the standard pagination, rather than appending a query string to the url, ie
Creating pretty urls was easy enough using the format parameter of paginate_links()
$args = array( 'format' => 'cpage/%#%', 'current' => $cpage, 'total' => $custom_query->max_num_pages, 'type' => 'array', 'prev_text' => __('Previous'), 'next_text' => __('Next'), ); $paging = paginate_links( $args );
The problem I'm having is with needing to then rewrite those urls back to a query string when the page is visited, because WP doesn't recognise my 'cpage' variable within a pretty url.
So I'm rewriting the urls in .htaccess like this
RewriteRule ^/posttype/([^/]*)/cpage/([0-9]*) /posttype/$1/?cpage=$2 [QSA]
and I've verified this rule should rewrite the way I expect using http://martinmelin.se/rewrite-rule-tester/. When applying the rule to the .htaccess on my site however I get a 404 when visiting pagination links and I don't understand why that is. Paging works just fine if I don't use pretty urls.
I've used mod_rewrite many times in the past, but never with WP. Are there any gotchas I should be aware of that might affect what I'm trying to do, or is there a better way to achieve this?
Post type registration using Toolset Types plugin:
WP_Post_Type Object ( [name] => deal [label] => Deals [labels] => stdClass Object ( [name] => Deals [singular_name] => Deal [add_new] => Add New [add_new_item] => Add New Deal [edit_item] => Edit Deal [new_item] => New Deal [view_item] => View Deal [search_items] => Search Deals [not_found] => No Deals found [not_found_in_trash] => No Deals found in Trash [parent_item_colon] => Parent text [all_items] => All items [archives] => All items [insert_into_item] => Insert into post [uploaded_to_this_item] => Uploaded to this post [featured_image] => Featured Image [set_featured_image] => Set featured image [remove_featured_image] => Remove featured image [use_featured_image] => Use as featured image [filter_items_list] => Filter posts list [items_list_navigation] => Posts list navigation [items_list] => Posts list [menu_name] => Deals [enter_title_here] => Enter title here [name_admin_bar] => Deal ) [description] => The link between compare and operator [hierarchical] => [exclude_from_search] => 1 [publicly_queryable] => 1 [show_ui] => 1 [show_in_menu] => 1 [show_in_nav_menus] => 1 [show_in_admin_bar] => 1 [menu_position] => [menu_icon] => dashicons-admin-post [capability_type] => post [map_meta_cap] => 1 [register_meta_box_cb] => [taxonomies] => Array ( ) [has_archive] => [query_var] => deal [can_export] => 1 [delete_with_user] => [_builtin] => [_edit_link] => post.php?post=%d [cap] => stdClass Object ( [edit_post] => edit_post [read_post] => read_post [delete_post] => delete_post [edit_posts] => edit_posts [edit_others_posts] => edit_others_posts [publish_posts] => publish_posts [read_private_posts] => read_private_posts [read] => read [delete_posts] => delete_posts [delete_private_posts] => delete_private_posts [delete_published_posts] => delete_published_posts [delete_others_posts] => delete_others_posts [edit_private_posts] => edit_private_posts [edit_published_posts] => edit_published_posts [create_posts] => edit_posts ) [rewrite] => Array ( [enabled] => 1 [with_front] => 1 [pages] => 1 [feeds] => [slug] => deal [ep_mask] => 1 ) [_toolset_edit_last] => 1482798189 [_wpcf_author_id] => 1 [wpcf-post-type] => deal [icon] => admin-post [slug] => deal [dashboard_glance] => 1 [custom-field-group] => Array (  => 1 ) [has_archive_slug] => [show_in_menu_page] => [query_var_enabled] => 1 [permalink_epmask] => 1 [rest_base] => deal [post_relationship] => Array ( [belongs] => Array ( [compare] => 1 [operator] => 1 ) ) [show_in_rest] => )