Ecommerce Shopify WordPress Discussion

Append custom post type to category url

I am trying to get a url when click on the link that has www.website/custom_post/category/post_name What I currently have is www.website/category/post_name. My current code <?php $post_type = get_post_type( $post->ID ); $args = array( 'post_type' => $post_type, 'posts_per_page' => -1, 'post_status' => 'publish' ); $the_query = new WP_Query( $args ); $my_categories = array(); if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); $terms = get_the_terms( get_the_ID(), 'category' ); if ( $terms && ! is_wp_error( $terms ) ) : foreach ( $terms as $term ) { if(!in_array($term->term_id, $my_categories)) $my_categories[] = $term->term_id; } endif; } wp_reset_postdata(); } if(sizeof($my_categories)) { ?> <h6>show only posy cats of post type test</h6> <?php foreach ($my_categories as $term_id) { $category = get_term_by('id', $term_id, 'category'); if($category->slug!="all-articles") { ?> <li><a href="<?php echo get_category_link( $category->term_id ) ?>"> <?php echo $category->name; ?> </a></li> <?php } } }
It's not about php but you can also do it with php too by making a Router. You can search in google for it. But also you can do it with .htaccess file and path redirects and rewrite rules. Here is code i prepared for your example write it into .htaccess in your server. <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # Rewrite rule for www.website/custom_post/category/post_name RewriteRule ^custom_post/category/([^/]+)/([^/]+)/?$ index.php?category=$1&post_name=$2 [L,QSA] # If the request is not a file or directory, pass it to index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]

February 4, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.