One simple option would be to add a parameter to the query string of the portfolio item (i.e. yousite.com/portfolio-item/?backto=portfolio-3
), then on the item page modify the ‘back’ link with JavaScript: if the backto
parameter exists then change the link to point to the portfolio specified in it.
Here’s some untested starter code. On the portfolio page (assuming you’re looping through portfolio items and printing links to their pages):
<?php $portfolio_name="whatever"; ?>
<a href="https://wordpress.stackexchange.com/questions/138758/<?php echo get_permalink() ."?backto=' . $portfolio_name; ?>"><?php the_title(); ?></a>
On the portfolio page:
$key_backto = (isset($_GET['backto']) ) ? $_GET['backto'] : '';
<a href="https://wordpress.stackexchange.com/questions/138758/<?php echo home_url("portfolio/' . $key_backto); ?>">Back to portfolio</a>
Related Posts:
- Add category base to url in custom post type/taxonomy
- Custom Post Type Permalink / Rewrite not working immediately
- has_term or in_category for Custom Post Types
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- WordPress Custom Post Type Category Page
- post count is wrong when using same taxonomy for 2 different CPT
- Custom-Taxonomy as categories: Remove “most-used” tab?
- Custom Permalinks for Custom Post Types and Taxonomies
- how to group custom post type posts by custom taxonomy terms
- Showing current taxonomy terms
- Unable to save custom taxonomy terms in a custom-built metabox
- Custom Taxonomy order by Custom Field
- Archive page for taxonomy of custom post type
- CPT tax slug conflict with post type slug
- Redirect a page based on last word in slug
- Exclude current post when getting related post on custom post type and taxonomy
- Show ACF field from custom taxonomy and display on the single template
- Custom post types, taxonomies, and permalinks
- How can I display my custom metaboxes on a custom post template?
- How to specify URLS for custom posts & taxonomies
- Taxonomy.php Not Showing Posts
- Display custom post type in hierarchical order with get_terms
- Am unable to reset a query properly
- Customize my custom taxonomy table in Admin panel
- Custom-Posttype & Custom Taxonomy WP_Query
- Add custom taxonomy to post content body?
- Custom post type url with category
- Limit amount of posts made within a custom taxonomy
- Issue on Creating Custom Tax Term Dynamically From Another CPT Meta-box On Publish
- Redirect 404 page with ID in slug to associated page with same ID in slug
- Custom taxonomy rewrite with query var returns %2F in URL
- Querying Custom Post Type, ordering by Custom Taxonomy Pagination Not Working
- Custom post type and taxonomy permalinks
- Exclude custom taxonomy term posts from custom post loop
- Displaying custom-taxonomy-terms sorted by parent/child-hierarchy?
- Create a permalink structure with custom taxonomies and custom post types gives 404
- Not Able To Render Single-CustomPostType.php File
- Retrieve custom post types by custom taxonomies with WP_Query
- How do I add a Custom Post Type that looks and behaves exactly the same as Posts?
- Custom URL redirect in WP
- Custom Post type & Taxonomy 404
- Using page slug in wp_query
- Custom taxonomy (categories) on custom post type return no results
- Custom taxonomy wp_query woes.
- previous_post_link in same taxonomy in custom post type
- Remove taxonomies using register_post_type_args
- Different options per post type in WP_Query
- Change custom taxonomy archive permalink
- Display both parent and child custom taxonomy / content
- Custom Category Walker with Image, Fallback to Most Recent Post in Category Image
- Get template part with CPT and Custom Taxonomy conditionals
- Displaying One Custom Post Type’s Content On Single Post of Another Custom Post Type
- Is there a way to make child posts inherit parent post terms?
- Custom post types category
- Query Custom Post by taxonomy multiple categories
- How to Control CSS Class Visiblity From WordPress Admin Panel based on Tax Terms
- Problem retrieving informations and displaying desired structure with custom post type and taxonomy
- Advanced archive url structure (category, tag and date)
- Setup page template array in a custom post type
- Best Way to Query Custom Taxonomies Used on Custom Post Type
- Change Dropdown jQuery to show/hide but with default place holder that shows all
- Get Posts List of Current Selected Custom Taxonomy in Shortcode
- Custom taxonomy terms as children of multiple custom post types
- Custom Taxonomy and Categories
- custom taxonomy pagination 404 error
- Archive page of CPT’s custom Taxonomy
- WordPress CPT Taxonomy Dashboard Search – How to include taxonomy in search?
- Get the taxonomy value in the post loop inside the archive page
- How to show related posts of category on post within custom posttype
- Post Tags not working for Custom Post type
- Filter in Custom post type to find the parent post
- Excluded Custom Taxonomy Term Posts Displaying in loop
- Listing all custom posts having a specific taxonomy whatever the terms
- Custom search for a custom post type in WordPress
- How can I group by Taxonomy on Custom Post Type while filtering out based on custom Meta
- Create a Hierarchical List of Custom Taxonomies AND Posts
- Custom URL for Custom Post Type & Custom Taxonomy Term
- Previous/Next custom post links within custom taxonomy
- Making permalink for custom post type/custom taxonomy. Stuck with 404 in the single post
- Custom Taxonomy page redirecting to 404 page
- Pretty permalink structure with multiple (AND OR) taxonomies
- Filter a custom taxonomy from displaying a button all other taxonomies can show
- Override “Parent” input for custom taxonomy
- Problem with type plugin and custom taxonomies
- WordPress Custom taxonomy template
- How can I add a “fake” parent into the permalink?
- Custom post type – two taxonomies
- How to display custom post types AND regular posts separately on a shared taxonomy archive?
- Why is this custom post type defaulting to archive.php?
- Check if taxonomy is attached to at least one post in a post-type
- Getting (Invalid) when adding custom taxonomy of custom post type link in menu [closed]
- Display custom taxonomy posts of custom post types
- Looping taxonomy in taxonomy?
- Missing categories for Custom Taxonomy and Custom Posts
- Show one of the taxonomies always as default
- Custom Post type as Taxonomy
- Get X posts with the same terms as the current post (custom post type and custom taxonomy)
- From form submission values – dynamically update CPT “has_archive” slug and custom taxonomy “rewrite” slug value
- Create a hierarchical list of posts that’s grouped and nested by category
- Show a wordpress custom post condtionally using a category term