Ecommerce Shopify WordPress Discussion

WordPress – displaying archive and single posts on different custom post type

I am relatively new to developing with Wordpress, I’m a designer first, developer second. I am creating a directory website. I have a members login area where users create a post under the post type, “my-business”. They then access their post for editing from the front-end once logged-in at; I have the above working. Now where I am stumped is, I want to display an archive and the posts data mentioned above under a different post type “business” for non logged-in users at a url like this; (as archive) and as the post. I’m not sure if I’m going about this the wrong way, any tips or advice would be appreciated. Thank you in advance. If I use a WP query loop calling the custom post type “my-business” in the archive-business.php file the title and all permalinks want to go to the original post under “my-business” instead on “business”
Keeping everything that you have working so far, the way I would do this is: Create a new post type: business. Use the wp_insert_post hook: to detect when a post of type "my-business" is created/updated. When this happens, check to see if a post of type "business" exists with this same slug, and if not, create it. If needed, open and update each of your my-business posts so that a business post is created for each, or write a script to loop through them all and take care of this. To handle the business archive page, use the pre_get_posts hook: Inside the callback, test to see if a business archive page is being accessed, and if it is, switch to the my-business post-type ( $query->set( 'post_type', 'my-business' ); ) This code will go in functions.php, or a plugin. This will make it so that when someone visits the /business page, they see a list of the posts of type my-business. In archive-business.php, instead of outputting the permalinks (which would now be links to the /my-business/xyz), get_the_permalink and replace 'my-business' with 'business' - now all the links on this page will go to '/business/xyz'. In single-business.php inside the loop, collect the slug of the post and use it to query for the post of post_type my-business that has the same slug - this will give you access to all the values the business owner has set for the business and you can display them here however you like.

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.