Home › Toolset Professional Support › [Resolved] Importing 800+ posts, need to support multiple CPTs with taxonomy.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+01:00)
Tagged: Post-relationship
This topic contains 14 replies, has 2 voices.
Last updated by Brian 5 years, 2 months ago.
Assisted by: Nigel.
Howdy, I'm hoping someone can help me with the best method for solving the following while migrating a large site:
Part of the site has two types of custom posts in a many-to-many relationship, both will need to be represented on the site with list views as well as single post views:
- Episodes
- Contributors
Episodes can have multiple Contributors.
I'm planning to import over 800 episodes with WP All Import Pro and Toolset Types. Here's the one piece I can't figure out how to accommodate:
A contributor can have one or multiple roles: sound engineer, writer, director, etc. I'm getting stuck on how to prepare the Contributor CPT as well as the episode spreadsheet for a successful import due to the roles. I don't want to have a Writer CPT, Sound Engineer CPT, etc.
Instead, I'd prefer to just add a category taxonomy to Contributors where the different roles are simply categories. For example, I could just select which roles (categories) a Contributor fills:
Joe Smith
[ ] Author
[ x ] Sound Engineer
[ x ] Director
[ ] Producer
My plan is to first import the Contributors with their corresponding categories, then import the Episodes CSV.
When I import the Episodes CSV, I need it to see the relationship to the Contributor(s) and understand the appropriate role that person is filling for that episode. You can see the screenshot from my CSV. Some Contributors are sometimes filling two roles on the same project.
I just don't know if this is the right way to solve this (can't figure out how WP All Import could understand the Contributor roles) or if I need some kind of intermediary pick list or something. Stymied.
Any advice would be great.
Thanks!
Brian
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+01:00)
Hi Brian
Before turning to the question of how to import the data, it seems like your set-up is a little off to me.
Basically, using a taxonomy assigned to contributors for the role would mean they always have that same role.
If you mark a contributor as a Director then they would always be a Director, regardless of the Episode.
From your screenshot it looks like different contributors can have different roles on different episodes.
So however you store the role it needs to know the context of the episode-contributor combination, e.g. Phil Lollar is writer on episode S02E08 while he is a director on episode S02E10.
That's what "relationship fields" are for, they are custom fields tied to a particular connection in a relationship.
(In terms of implementation, custom fields are stored in wp_postmeta and always belong to a post. So if you make a relationship between Episode and Contributor post types Toolset will create a hidden custom post type—known as the intermediate post type—which stores the custom field values. Every time you connect and Episode to a Contributor, e.g. Phil Lollar and S02E08, an intermediate post is created which can store custom fields specific to that connection, i.e. the role in this case.)
So, first make sure your Episode<<>>Contributor relationship has a "Role" relationship custom field, I'd suggest a select field. If someone has more than one credit on an episode (e.g. writer, and director) then you would connect them twice, specifying a different role each time.
If that makes sense and you successfully set up the relationship fields, we can look at preparing the data to import (I'll need to set up a test site to double-check what's required/possible with relationship fields so I'll wait until you confirm the above is okay).
Nigel, thanks I was heading the wrong direction.
I've successfully setup the Roles select field inbetween Contributors and Episodes (see attached screenshot).
I suppose I will need to setup a Roles custom field inbetween Contributors and Books as well.
This leads to two final questions:
1) Is it possible to create my episodes import sheet in such a way that it can import all 800 posts as well as the relationships to contributors and their roles? (I'm wondering if I should just import all episode data except relationships and then go add them manually.
2) When I'm designing an episode page, is it possible (using views) to list all contributors by roles? So:
Sound designers: Will Smith, Nancy Wilson
Writers: Bob Lutrell
Thanks for helping me sort this! Massive appreciation on this end
Brian
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+01:00)
1) It should be possible using the Types add-on for the WP Ultimate CSV Importer Pro plugin: https://toolset.com/documentation/user-guides/export-import/how-to-import-content-into-wordpress-using-csv/import-csv-ultimate-csv-importer-plugin/how-to-import-posts-from-csv-files-and-maintain-relationships-when-using-the-csv-importer-plugin/
If you are a WP All Import user they have a similar add-on which never made it out of beta but which I think works.
2) Tricky. Wouldn't be if they were a taxonomy, but that won't work as previously described.
It's actually not that tricky, but I think you need to add a View for each role you are outputting. You can recycle a single View by passing which role you want outputting as a shortcode attribute, as described here: https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/
Remember, the fields are actually stored on the intermediate post type, so the View for the Content Selection will need to query the intermediate post type. You then add a Query Filter to only return posts where the role custom field matches that passed via shortcode attribute (you could start out with a static value for testing).
Then to the output section.
The View will be iterating over the intermediate posts, but you want to output fields (i.e. the post title) of the related Contributor post. You do that by using the Post Selection tab when inserting a field using the Fields and Views button if you are using the classic Views editor, and specifying that the source of the field should be the specified related post.
Use the Loop Wizard and choose List with separators for the output format, add the post title field, and use the Edit button so that you get the Post selection tab described above where you can specify and alternative source.
Excellent!
Are we able to achieve the same on #2 with the new Blocks tool? We just changed the site over from Views to Blocks, but can revert it if the functionality needed from #2 isn't possible.
Thank you Nigel.
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+01:00)
I already finished for the day, but let me just jump in and say that passing shortcode arguments isn't supported in the Blocks UI for Views yet, but you don't have to go all-in one way or the other.
Go to Toolset > Settings and choose to expose both the Blocks and classic Views UI, then use classic Views just in this case. You can even adopt a hybrid approach where you create the View and add the settings with classic Views, then use the Loop Wizard so that it sets up a linked content template for the output, then design that template with Blocks.
When it comes to inserting the View and providing the shortcode attributes you might need to use a Classic block or a Custom HTML block where you can edit the shortcode to add the shortcode attribute as required.
Thank you Nigel. I will implement this and let you know how it goes. I may have hit one blocker:
I only appear to be able to add one of each contributor to an episode. So, if I've added Joe Smith as a Writer. Joe Smith is no longer an option to add again as another role.
Is there some way to enable multiple versions of the same contributor? Thanks!
Nigel,
I was able to successfully setup all post types and then connect them all using the WP All Import Beta plugin when I uploaded the Episodes spreadsheet last.
My final questions are about contributors and roles still.
If I attempt to add a contributor twice to an episode, the autosearch won't find the contributor the second time because he/she is already in use.
However, when I did the Episode import, the site was able to create the same person twice as a contributor on an Episode. I was not able to figure out how to assign a role on import, so my plan was to just go back through and assign them manually. However, when I'm inside of an episode and click "quick edit" on a contributor, the roles dropdown is not available.
If I go update that contributor's post (ie: simply select "publish" again) then go back to the episode and refresh, the roles dropdown suddenly becomes available in the Episode.
Any thoughts about this would be very helpful. I'll be out of office for a few days but will check back in and close this out when I am back in. Thanks!
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+01:00)
Ah, Brian, I may have led you astray.
You are right, there is a—somewhat arbitrary—limitation with M2M relationships in that you cannot connect the same posts more than once (e.g. a speaker cannot speak more than once at the same conference).
I'd forgotten about that until you ran into it. (We have a feature request to remove some of these restrictions in post relationships, and I'd encourage you to submit a request for it so that the product manager is reminded of the demand for it: https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/.)
I'm not sure how the import process managed to create multiple associations, they evidently don't use the official API (which returns this message if you try with toolset_connect_posts: These two elements are already associated and the relationship doesn't allow non-distinct associations). In any case, you cannot rely on this as other functionality, including retrieving and displaying the data, is liable to fail because of this.
Which requires a re-think, so that your custom field for the role needs to be something that accepts multiple options, e.g. a checkboxes field, and you make only a single connection between an Episode and a Contributor, and the custom field stores all of the roles for that combination.
Sorry if that means you re-doing some of the work.
Thanks Nigel,
That makes sense. So, if I use a multi-select custom field. Is there a way to query/sort by these custom field values?
For example, if I want to list all contributors who are writers.
Best,
Brian
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+01:00)
There is no such thing as a multiselect field type in Toolset. When adding search filters to a View you can choose to display certain field types as multi-select, but there isn't a field type where you input the data as a multi-select.
Certain field types allow you to have multiple instances of the same field, but if you want one field where one or more options can be chosen at the same time, then the only field type that supports this is the checkboxes field type.
If you add that to your many-to-many relationship then an intermediate post type is created to store the custom field values for each connection. Set up the checkboxes custom field with the required options (be sure to specify save nothing to the database when unchecked and have each option save a different value when checked).
Then go to Toolset > Post Types and edit the intermediate post type belonging to this relationship.
You'll need to go to the options and make sure it *is* publicly_queryable and *is not* excluded from search.
You can then create a View to query the intermediate post type.
Because you can only filter something by its own properties, if the custom field is stored against the intermediate post type, then if you want to filter by this custom field, you must query this post type.
With a many-to-many relationship using an intermediate post type, it can help to visualize it like so:
left right \ / \ / intermediate
By convention, the left is known as the parent and the right is known as the child.
So, the View will query intermediate posts (including a Query Filter for the custom field belonging to them), which means that the output section of the View will be iterating over intermediate posts.
But you are unlikely to want to display fields from the intermediate post (e.g. the title), you will surely want to display fields of either the left or right posts connected to these intermediate posts.
In the output section when you insert fields you can specify an alternate source for the field than the current post, specifically, in this case, you can choose the related left (parent) or right (child) post as the field source.
So, although you are querying the intermediate posts, you are outputting fields of the left or right posts in the relationship.
Does that make sense?
Wow, thank you for that explainer. I've almost got it and then will close this out.
I have the intermediary checklist in place.
I'm building the view to pull the associated contributors for an episode. It pulls the correct contributors, but I'm a little confused on how to limit the view to the contributors who match up with a checkbox value (for example, "Writer"). I'll attach a few screenshots to show you what I've got.
- How I setup the Writer checkbox
- An example of how I've assigned these roles to contributors in an episode
- How I'm pulling just the contributors associated with a contributor - episode relationship
My loop is just this:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-item index=other]
[wpv-post-title],
[wpv-item index=last]
[wpv-post-title]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-layout-end]
Output:
[wpv-filter-meta-html]
[wpv-layout-meta-html]
It successfully prints the three contributors on the post: Bob Luttrell,Phil Lollar,Steve Harris
The last piece is I've fiddled with the different view filters and haven't had luck limiting to just a Writer or Sound Designer. My final screenshot shows how I tried to match a string by adding the custom field filter to my view query. When I do this, no contributor names print.
Hopefully, this makes sense. I'm probably misunderstanding one of your directives.
Thanks again!
Brian
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+01:00)
Your View is querying the wrong thing in the first place.
This is from my last update:
You can then create a View to query the intermediate post type.
Because you can only filter something by its own properties, if the custom field is stored against the intermediate post type, then if you want to filter by this custom field, you must query this post type.
Your View needs to Query the intermediate post type where the relationship fields are stored. They are not stored on the Contributor post type, so you cannot filter Contributors by the Role relationship field, you can only filter the intermediate post type by the Role field.
Your View will want 2 Query Filters, the first a relationship filter to "show" intermediate posts connected to the current Episode, and a second filter to limit the results according to the specified Role.
Then in the output section, recalling that it will be iterating over intermediate posts, to output the title of the related contributor you would need to specify an alternate source for the field.
If you use the Fields and Views button to insert the post title, there is a Post Selection tab where you can specify that the source for the post title should be the related Contributor.
That will add an item attribute to the wpv-post-title shortcode (something like item="@episode-contributor.child").
Aha! I missed the step for making that intermediate post type publicly queryable, so I wasn't seeing it as an option. Sorry about that.
Thanks for your amazing patience and attention to detail! I now have it working and am using linked titles so the contributor name is clickable.
This is my loop code as an FYI:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-item index=other]
[wpv-post-link item="@episode-and-contributor.child"],
[wpv-item index=last]
[wpv-post-link item="@episode-and-contributor.child"]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]
Toolset opens up a lot of possibilities!
Thanks Nigel
My issue is resolved now. Thank you!