最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

advanced custom fields - One post but two separate permalink structure and template views

matteradmin10PV0评论

I am wondering if there is code or a plugin would help to solve my problem.

I run a news website. Rather than make a separate custom post type and separate that from the actual story post that eventually gets published to the public. I was thinking I could make an assignment Advanced Custom Fields field group attach it to the story post - to have photo and reporter assignments for each story post and then have one permalink that displays the final story template and another permalink view that displays the assignment for the photographer and reporter that is then sent to the person.

This way the assignment stays with the story at all times. I have attempted to use post 2 post and acf child post to attach a custom post type to another custom post type but they both dragged my site down to a crawl.

In other words I am looking to display one set of ACF fields one way but then another set of ACF fields another way all within the same "post"

The idea is that I want to keep everything "connected" within the CMS. FO example an editor is looking at a story in the CMS but needs to refer to what the original assignment was.

one idea is to use categories but is there a way to have two separate categories for one post -- one category called "assignment" for the assignment permalink and the other normal such as "news" "sports" etc.

any ideas are appreciated.

I am wondering if there is code or a plugin would help to solve my problem.

I run a news website. Rather than make a separate custom post type and separate that from the actual story post that eventually gets published to the public. I was thinking I could make an assignment Advanced Custom Fields field group attach it to the story post - to have photo and reporter assignments for each story post and then have one permalink that displays the final story template and another permalink view that displays the assignment for the photographer and reporter that is then sent to the person.

This way the assignment stays with the story at all times. I have attempted to use post 2 post and acf child post to attach a custom post type to another custom post type but they both dragged my site down to a crawl.

In other words I am looking to display one set of ACF fields one way but then another set of ACF fields another way all within the same "post"

The idea is that I want to keep everything "connected" within the CMS. FO example an editor is looking at a story in the CMS but needs to refer to what the original assignment was.

one idea is to use categories but is there a way to have two separate categories for one post -- one category called "assignment" for the assignment permalink and the other normal such as "news" "sports" etc.

any ideas are appreciated.

Share Improve this question asked Jan 10, 2019 at 22:19 sethgsethg 313 bronze badges 1
  • How familiar are you with PHP? If you are comfortable editing your custom post type's single view template file you could achieve this without messing with permalink structure. – Justin Waulters Commented Jan 11, 2019 at 1:58
Add a comment  | 

1 Answer 1

Reset to default 0

If the people who need to see the reporter assignment / photographer assignment information all have WordPress logins, it would be a lot more secure to just have postmeta that is only visible when in wp-admin. You can create a custom column so that when you view all your Posts, one of the columns shows the reporter, and another shows the photographer. (See How can I add columns to the post edit listing to show my custom post data?)

Or, if they all have WP logins and you want them to see this data when viewing individual posts on the front end, you could

  1. Add postmeta boxes for "photo assignment" and "reporter assignment" to your posts. (See Problem in custom meta boxes)

  2. (In a child theme) update your single.php file. Wherever you want to conditionally show the assignment, add

if( is_user_logged_in() ) { echo 'Reporter: ' . get_the_field('reporter_assignment'); echo 'Photographer: ' . get_the_field('photographer_assignment'); }

If they don't all have WordPress logins and you are okay with the possibility that someone in the public might see these assignments, you can still handle everything with plain postmeta (no need for ACF). You would:

  1. Add postmeta boxes for "photo assignment" and "reporter assignment" to your posts.

  2. (In a child theme) update your single.php file. Wherever you want to conditionally show the assignment, add

if($_GET['show_assignments'] == true) { echo 'Reporter: ' . get_the_field('reporter_assignment'); echo 'Photographer: ' . get_the_field('photographer_assignment'); }

The public will see your regular URL, such as example/post/, and whoever needs to see the additional details will need to use the URL example/post/?show_assignments=true

  1. You should also make sure to set the canonical URL so Google knows to index the version without query strings. Most SEO plugins will handle this for you.

  2. If you have Google Analytics you should also tell it to ignore the show_assignments query var, so it doesn't show visits to the query-string version separately from visits without the query string.

Post a comment

comment list (0)

  1. No comments so far