Creating archive like functionality through birectional relationships

I could use some guidance in something where I may have developed myself into a corner. Here is the situation I have:

  • CPT: Communities
  • CPT: Innovators
  • CPT: Success Stories

Any Innovator or Success story needs to be tied to a Community. I’ve attempted to do this through a ACF Bidirectional relationship field. I did this instead of a taxonomy because I didn’t want them to have to manage a community taxonomy and a community post type every time a new one was added. It also makes listing associated innovators and success stories on a community page relatively simple. The problem is now that I am doing it that way, I can’t use the archive system.

What I need to be able to do is list the communities, and have them link to a list of their associated innovators or success stories depending on the intent. Ideally the titles of these listing pages can be dynamic as well. There is an old plugin called CPT-onomies that converts a CPT into a taxonomy for another but I am hesitant to use it since it has been 2 years from last update. Is there an elegant and dynamic solution to this or should I just make taxonomies?

For a visual representation, here is the design. Slides 4 and 5 are good example.

Many thanks.

Help with Elementor Pagination archive 404 problem

The pagination links in CPT archive created with Elementor Pro get a 404.

I’ve spend a full day searching and trying everything I found on Google with search "CPT Elementor archive pagination 404": readjust posts per page in write settings, tweak Function.php, tweak cpt php (in my case as a custom made plugin , see herafter) and some other… none resulting in a partial or full solution.

Example of page resulting in 404 is here: (access with admin/admin). The standard archive pagination links work perfectly ( This is test site, same happens on proper website.

This is driving me crazy. I’m doing my best with the beginner knowledge I have. Please help.

    add_action('init', 'CT_temoignage');     function CT_temoignage()     {         register_post_type('post-temoignage', array(          'label' => __('Témoignages'),          'singular_label' => __('Témoignage'),          'public' => true,          'has_archive' => true,          'show_ui' => true,          'capability_type' => 'post',          'hierarchical' => false,          'taxonomies'=> array ('category', 'post_tag'),          'supports' => array('title', 'author', 'editor', 'thumbnail','excerpt','revisions','page-attributes','publicize', 'wpcom-markdown'),          'menu_position'=>5, 'rewrite' => array('slug' => 'temoignages','with_front' => true),                             // 'query_var' => 'temoignage'           'publicly_queryable' => true,     'query_var' => true,     'rewrite' => false,         ));         add_theme_support( 'post-thumbnails' );                  global $  wp_rewrite; $  gallery_structure = '/temoignages/%post-temoignage%'; $  wp_rewrite->add_rewrite_tag("%post-temoignage%", '([^/]+)', "post-temoignage="); $  wp_rewrite->add_permastruct('post-temoignage', $  gallery_structure, false);     }     // Add filter to plugin init function add_filter('post_type_link', 'post_temoignage_permalink', 10, 3);     // Adapted from get_permalink function in wp-includes/link-template.php function post_temoignage_permalink($  permalink, $  post_id, $  leavename) {     $  post = get_post($  post_id);     $  rewritecode = array(         '%year%',         '%monthnum%',         '%day%',         '%hour%',         '%minute%',         '%second%',         $  leavename? '' : '%postname%',         '%post_id%',         '%category%',         '%author%',         $  leavename? '' : '%pagename%',     );       if ( '' != $  permalink && !in_array($  post->post_status, array('draft', 'pending', 'auto-draft')) ) {         $  unixtime = strtotime($  post->post_date);               $  category = '';         if ( strpos($  permalink, '%category%') !== false ) {             $  cats = get_the_category($  post->ID);             if ( $  cats ) {                 usort($  cats, '_usort_terms_by_ID'); // order by ID                 $  category = $  cats[0]->slug;                 if ( $  parent = $  cats[0]->parent )                     $  category = get_category_parents($  parent, false, '/', true) . $  category;             }             // show default category in permalinks, without             // having to assign it explicitly             if ( empty($  category) ) {                 $  default_category = get_category( get_option( 'default_category' ) );                 $  category = is_wp_error( $  default_category ) ? '' : $  default_category->slug;             }         }         $  author = '';         if ( strpos($  permalink, '%author%') !== false ) {             $  authordata = get_userdata($  post->post_author);             $  author = $  authordata->user_nicename;         }         $  date = explode(" ",date('Y m d H i s', $  unixtime));         $  rewritereplace =         array(             $  date[0],             $  date[1],             $  date[2],             $  date[3],             $  date[4],             $  date[5],             $  post->post_name,             $  post->ID,             $  category,             $  author,             $  post->post_name,         );         $  permalink = str_replace($  rewritecode, $  rewritereplace, $  permalink);     } else { // if they're not using the fancy permalink option     }     return $  permalink; }    ?> 

Landing in 404 Page on Navigating to Custom Taxonomy Archive

Can you please take a look at this post and let me know how I can navigate to Taxonomy URL properly? Having a CPT called movie and a Taxonomy called genre how I can navigate into archive of taxonomy.php and taxonomy-genre.php

<?php      flush_rewrite_rules( false ); function custom_post_type_movie() {     $  labels = array(         'name'                  => 'movies',         'singular_name'         => 'movie',         'menu_name'             => 'Movies',         'name_admin_bar'        => 'Post Type',         'archives'              => 'Item Archives',         'attributes'            => 'Item Attributes',         'parent_item_colon'     => 'Parent Item:',         'all_items'             => 'All Items',         'add_new_item'          => 'Add New Item',         'add_new'               => 'Add New',         'new_item'              => 'New Item',         'edit_item'             => 'Edit Item',         'update_item'           => 'Update Item',         'view_item'             => 'View Item',         'view_items'            => 'View Items',         'search_items'          => 'Search Item',         'not_found'             => 'Not found',         'not_found_in_trash'    => 'Not found in Trash',         'featured_image'        => 'Featured Image',         'set_featured_image'    => 'Set featured image',         'remove_featured_image' => 'Remove featured image',         'use_featured_image'    => 'Use as featured image',         'insert_into_item'      => 'Insert into item',         'uploaded_to_this_item' => 'Uploaded to this item',         'items_list'            => 'Items list',         'items_list_navigation' => 'Items list navigation',         'filter_items_list'     => 'Filter items list',     );     $  args = array(         'label'                 => 'movie',         'description'           => 'Post Type Description',         'labels'                => $  labels,         'supports'              => array( 'title', 'editor' ),         'taxonomies'            => array( 'genre' ),         'hierarchical'          => false,         'public'                => true,         'show_ui'               => true,         'show_in_menu'          => true,         'menu_position'         => 2,         'show_in_admin_bar'     => true,         'show_in_nav_menus'     => true,         'can_export'            => true,         'has_archive'           => true,         'exclude_from_search'   => false,         'publicly_queryable'    => true,         'capability_type'       => 'page',     );     register_post_type( 'movie', $  args );  } add_action( 'init', 'custom_post_type_movie', 0 );   function genre() {      $  labels = array(         'name'                       => 'Movie Genres',         'singular_name'              => 'Taxonomy',         'menu_name'                  => 'Genre',         'all_items'                  => 'All Items',         'parent_item'                => 'Parent Item',         'parent_item_colon'          => 'Parent Item:',         'new_item_name'              => 'New Item Name',         'add_new_item'               => 'Add New Genre',         'edit_item'                  => 'Edit Item',         'update_item'                => 'Update Item',         'view_item'                  => 'View Item',         'separate_items_with_commas' => 'Separate items with commas',         'add_or_remove_items'        => 'Add or remove items',         'choose_from_most_used'      => 'Choose from the most used',         'popular_items'              => 'Popular Items',         'search_items'               => 'Search Items',         'not_found'                  => 'Not Found',         'no_terms'                   => 'No items',         'items_list'                 => 'Items list',         'items_list_navigation'      => 'Items list navigation',     );     $  args = array(         'labels'                     => $  labels,         'hierarchical'               => true,         'public'                     => true,         'show_ui'                    => true,         'show_admin_column'          => true,         'show_in_nav_menus'          => true,         'show_tagcloud'              => true,     );     register_taxonomy( 'genre', array( 'movie' ), $  args );  } add_action( 'init', 'genre', 0 ); ?> 

In my theme directory I have 3 files for taxonomy like

enter image description here

in each of them I have code like

<?php get_header(); ?>  <main id="main" class="site-main" role="main">     <?php      if ( have_posts() ) :          while ( have_posts() ) : the_post();              // Display post content             the_title();         endwhile;      endif;      ?> </main>  <?php get_footer(); 

in both http://wpdev/genre and http://wpdev/movie/genre I am landing in 404 page

enter image description here

sort CPT on Custom Taxonomy Archive page

I have created a custom post type called "al_product" and attached to it a custom taxonomy called "product_category".

In my archive-product_category.php I have this (relevant) code:

            if ( $  termchildren  ) {                 // we have kids...just show the terms.                            $  i=1;                 foreach ( $  termchildren as $  child ) {                     if ($  i % 2 == 0) {                         echo '<div class="tax-entry flex">';                     } else {                         echo '<div class="tax-entry flex" style="flex-direction: row-reverse;">';                     }                     ?>                         <figure class="wp-block-media-text__media">                             <?php if ( get_field('product_category_img', $  child) ) echo wp_get_attachment_image( get_field('product_category_img', $  child), 'full' ) ;?>                         </figure>                         <div style="flex:60% 0 0;" class="wp-block-media-text__content">                             <h2><?php echo $  child->name ;?></h2>                             <p>                                 <?php                                 if (get_field('short_description', $  child )){                                      echo get_field('short_description', $  child );                                 }else{                                     echo $  child->description;                                 }?>                             </p>                             <?php                             // Get (at most) 2 "product" posts in the child term.                             $  posts = get_posts( array(                                 'post_type'      => 'al_product',                                 'posts_per_page' => 2,                                 $  taxonomy_name   => $  child->slug,                             ) );                              // If there's exactly 1 post, use the post permalink.                             if ( 1 === count( $  posts ) ) : ?>                                 <a class="button" href="<?php the_permalink( $  posts[0] ); ?>">See this Product</a>                             <?php // Else, use the term link.                             else : ?>                                 <a class="button" href="<?php echo esc_url( get_term_link( $  child, $  taxonomy_name ) ); ?>">See this Series</a>                             <?php endif; ?>                          </div>                     </div> <!-- END FLEX -->                     <?php                     $  i++;                 }             } else {                  // no the products                 echo '<div class="productCategories grid">';                 while ( have_posts() ) : the_post();                     ?>                      <div class="product_cat">                         <a href="<?php the_permalink();?>">                             <?php the_post_thumbnail('small');?>                             <h2><?php the_title();?></h2>                             <?php                             $  subtitle = get_field('subtitle');                             if ( $  subtitle ) {                              echo '<h3 class="entry-subtitle">'.$  subtitle.'</h3>';                             }                             ?>                         </a>                         <?php //if (get_field('specs')['part_number']) echo '<span>'.get_field('specs')['part_number'].'</span>';?>                     </div>                  <?php                 endwhile;                 echo '</div>';             } 

The section I’m questioning is when there are no kids so we show products.

Currently this is returning the products correctly but sorting by title. I would like to sort by menu_order.

I added this to my functions.php:

add_action( 'pre_get_posts', 'rt_change_product_sort_order');  function rt_change_product_sort_order($  query){     if(get_query_var( 'product_category' )):        //Set the order ASC or DESC        $  query->set( 'order', 'DESC' );        //Set the orderby        $  query->set( 'orderby', 'menu_order' );     endif;     }; 

To no avail. I’ve also tried replacing the "If" statement with each of these:

if(is_post_type_archive( 'product_category' )): if(get_query_var( 'product_category' )): if(get_query_var( 'al_product' )): 

What am I missing here?

Conditional widget for a listing archive page

I am building a listing website (using ListingPro theme)

Inside the Listing Archive page I added some advertising widgets and I need to add conditions to it so that different content is displayed according to the location.

For example, the user chooses location A, the widget displays ads for A. The user chooses location B, displays for B, and so on.

I tried using the Widget options plugin but I don’t know how to set the logic condition here: Widget options

Using the conditional tags from here:

This is the website I’m working on:

It has a search engine where you can choose a category and a location and then it shows a list of listings.

For example, if I search for the city of "Buenos Aires" it shows me the following link:

As you can see from the link Buenos Aires has the ID 1203. How could I set the logic condition inside the widget so that it shows according to the ID of the location you are looking for?

Any ideas? Thanks in advance!

How to properly replicate and archive at once

I have a 300GB database that is growing around 5GB a day. It stores time-based data, and as such, I currently have around 60 days of data. My main database server has a 450 GB NVMe, so I want to get a secondary server that has expandable cheap storage for old data.

The main server only really needs the last 15 days of data. So anything older than 15 days of data I want to move off to the secondary database which has slower but cheap storage. I think standard backup or archiving isn’t viable because I want to query the data at any given moment (maybe ~100 queries a day).

I want to kill two birds one stone here and I thought if I setup replication to the secondary server and then somehow indicate the cleanup stored procedure which delete records older than 15 days doesn’t propagate deletes to the slave.

Is this possible and recommended? If not, what is the best way to accomplish archived the data but to another server and allow querying. I suspect partitioning all of my tables but not all of my tables are time-based so I would need some way to move the time-based partitioned data over along with any FKs needed for it

PS: I won’t be relying on the secondary server as a backup but rather my main replication. I would then do offsite backups of the secondary server periodically

WordPress Sub Category Archive, Show Extra Empty Page Number in Pagination

This my code for sub category archive page:

                        <?php $  my_query = new WP_Query( array( 'posts_per_page' => 12, 'post_type' => 'post', 'paged' => get_query_var( 'paged' ), 'post_status' => 'publish', 'category__and' => array( 2 ) ) ); ?>                                 <?php if ($  my_query->have_posts()) : ?>                         <?php while ($  my_query->have_posts()) : $  my_query->the_post(); ?>                          //Contents Here//                          <?php endwhile; ?><?php endif; ?>                                            <?php wp_reset_postdata(); ?> 

Now I have 1 empty extra page number in pagination of my archive page.

For example I have only 3 pages of contents by I can See a number 4 link in pagination numbers who open’s an empty page without any posts in there.

Can you help me please?

Custom Post Type Archive Page URL

I created a custom post type called provider, and currently I have a URL structure like so:

  1. .com/provider/abc
  2. .com/provider/xyz
  3. etc…

Now I would like to add some content in the provider page, mostly for SEO reasons. After having a look at how archive pages are working, I found out that it would be best to just change the URL of the archive page for provider. So the new URL would be .com/provider-archive/ while keeping the same URL for the provider already in the system, so they would remain:

  1. .com/provider/abc
  2. .com/provider/xyz
  3. etc…

This way, I would be able to create a regular page and give it the /provider/ URL.

I am trying to do so by changing the rewrite, adding in a slug to be provider-archive. After doing all of this, and creating a new page with the URL /provider/, when I try to access said URL I still see the archive.

This is how my custom post type is set up:

/**  * Register Provider Meta Box  */  add_action('init', 'cpt_provider'); function cpt_provider() {      $  labels = array(         'name'               => _x('Providers', 'post type general name', 'mebo-cpt'),         'singular_name'      => _x('Provider', 'post type singular name', 'mebo-cpt'),         'menu_name'          => _x('Providers', 'admin menu', 'mebo-cpt'),         'name_admin_bar'     => _x('Provider', 'add new on admin bar', 'mebo-cpt'),         'add_new'            => _x('Add New', 'book', 'mebo-cpt'),         'add_new_item'       => __('Add New Provider', 'mebo-cpt'),         'new_item'           => __('New Provider', 'mebo-cpt'),         'edit_item'          => __('Edit Provider', 'mebo-cpt'),         'view_item'          => __('View Provider', 'mebo-cpt'),         'all_items'          => __('All Providers', 'mebo-cpt'),         'search_items'       => __('Search Providers', 'mebo-cpt'),         'parent_item_colon'  => __('Parent Providers:', 'mebo-cpt'),         'not_found'          => __('No Providers found.', 'mebo-cpt'),         'not_found_in_trash' => __('No Providers found in Trash.', 'mebo-cpt')     );      $  args = array(         'labels'             => $  labels,         'description'        => __('Description.', 'mebo-cpt'),         'public'             => true,         'publicly_queryable' => true,         'show_ui'            => true,         'show_in_menu'       => true,         'query_var'          => true,         'capability_type'    => 'post',         'rewrite'           => array( 'slug' => 'provider-archive' ),         'hierarchical'       => true,         'menu_position'      => null,         'menu_icon'          => get_template_directory_uri() . '/img/icons/Gun-512.png',         'supports'           => array('title', 'editor')     );      register_post_type('provider', $  args); } 

Is there anything that I’m missing?

Filter custom post types in archive

I want to filter my custom posts (pump) with a custom filter form on it’s archive page (archive-pump.php).

So, I wrote the form markup:

<form method="GET">     <label>Series</label>     <?php         if( $  terms = get_terms( array( 'taxonomy' => 'series', 'orderby' => 'name' ) ) ) :             echo '<select name="series">';             foreach ( $  terms as $  term ) :                 echo '<option value="' . $  term->term_id . '">' . $  term->name . '</option>'; // ID of the category as the value of an option             endforeach;             echo '</select>';         endif;     ?>     <button type="submit">Apply filter</button> </form> 

And I have this to output my custom posts:

<?php if(have_posts()) : while(have_posts()) : the_post(); ?>     <?php the_title( '', '', true ); ?> <?php endwhile; endif; ?> 

When I open my page (localhost/project/pumps) it looks fine. But when I submit my form I’m getting an 404 page.

I maybe need an seperate query to fetch all the $ _GET data. But I’m not getting to the step because of the 404 error.

What am I doing wrong? Thank you!