How to get pagination to work despite naming conflict?


I have been stomped for the past two days trying to understand wordpress’ permalink structure. Right now, I have a a custom post type called venue and I have a custom taxonomy venue-type (e.x. hotels, beds and breakfast). I rewrote the rules such that the links to a venue post are changed from venues/post-name to venues/venues-category/post-name. For the permalink of the archive page for venues, it’s simply remained as venues. For the permalink of the archive page for venue-type, it’s changed from venue-type/venues-category to venues/venues-category.

Now, the issue is that before changing the permalinks, there were no naming conflicts, and thus, pagiation worked completely fine. Now, however, pagiation does not work and I’m at my wit’s end. Does anybody know how to get pagiation to work with my new permalink structure?

Here is my custom post-type: venues

function venue_post_type() {
    register_post_type( 'venues',
        'labels' => array(
          'name' => __( 'Venues' ),
          'singular_name' => __( 'Venue' )
        'public' => true,
    'has_archive' => 'venues',
    'menu_icon' => 'dashicons-building',
    'menu_position' => 4,
    'supports' => array( 
    'rewrite' => array( 'slug' => 'venues/%venue_category%', 'with_front' => false ),
  add_action( 'init', 'venue_post_type' );

Here is my custom taxonomy for venues: venue-type

function register_tax_venue_type() {
  register_taxonomy('venue-type', array('venues'), array(
    'labels' => array(
      'name' => _x('Venue Types', 'Taxonomy General Name', 'venue-type'),
      'singular_name' => _x('Venue Type', 'Taxonomy Singular Name', 'venue-type'),
      'menu_name' => __('Venue Types', 'venue-type'),
      'all_items' => __('All Venue Types', 'venue-type'),
      'parent_item' => __('Parent Venue Type', 'venue-type'),
      'parent_item_colon' => __('Parent Venue Type:', 'venue-type'),
      'new_item_name' => __('New Venue Type', 'venue-type'),
      'add_new_item' => __('Add New Venue Type', 'venue-type'),
      'edit_item' => __('Edit Venue Type', 'venue-type'),
      'update_item' => __('Update Venue Type', 'venue-type'),
      'view_item' => __('View Venue Type', 'venue-type'),
      'separate_items_with_commas' => __('Separate Venue Types with Commas', 'venue-type'),
      'add_or_remove_items' => __('Add or Remove Venue Types', 'venue-type'),
      'choose_from_most_used' => __('Choose from the Most Used Venue Types', 'venue-type'),
      'popular_items' => __('Popular Venue Types', 'venue-type'),
      'search_items' => __('Search Venue Types', 'venue-type'),
      'not_found' => __('Not Found', 'venue-type'),
      'no_terms' => __('No Venue Types', 'venue-type'),
      'items_list' => __('Venue Types List', 'venue-type'),
      'items_list_navigation' => __('Venue Types List Navigation', 'venue-type')
    'hierarchical' => true,
    'public' => true,
    'show_ui' => true,
    'show_admin_column' => true,
    'show_in_nav_menus' => true,
    'show_tagcloud' => true,
    'rewrite' => array( 'slug' => 'venues', 'with_front' => false )
add_action('init', 'register_tax_venue_type');

Here is my function to replace %venue_category% such that the post slug goes from venues/venues-name to venues/venues-category/venues-name:

function venue_permalinks( $post_link, $post ){
  if ( is_object( $post ) && $post->post_type == 'venues' ){
      $terms = wp_get_object_terms( $post->ID, 'venue-type' );
      if( $terms ){
          return str_replace( '%venue_category%' , $terms[0]->slug , $post_link );
  return $post_link;
add_filter( 'post_type_link', 'venue_permalinks', 1, 2 );

Here are my rewrite rules

function venue_rewrite_rules($rules) {
  $newRules  = array();
  $newRules['venues/(.+)/(.+)/?$'] = 'index.php?venues=$matches[2]'; 
  $newRules['venues/(.+)/?$']      = 'index.php?venue-type=$matches[1]'; 
  return array_merge($newRules, $rules);
add_filter('rewrite_rules_array', 'venue_rewrite_rules');
Redwan Mohammed 2 years 2020-12-26T04:10:20-05:00 0 Answers 4 views 0

Leave an answer