Skip Navigation

[Resolved] Only show one version of a post relationship

This support ticket is created 2 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

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
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by Jamal 2 years, 3 months ago.

Assisted by: Jamal.

Author
Posts
#2238169

Tell us what you are trying to do?

I am working on a support section for a website where a visitor can search for information and there are up to three ways that media can be viewed.

Within my site I have three different post types, all linked together within 1-to-1 relationships. The post types are Articles, Videos & Slideshows. They are effectively the same (as in they provide the visitor with the same information but in different media types).

Every support question may not have all three media types so I don't think setting a default post type would work.

What I am trying to do is, when a search is performed only show one version and not display the linked related posts.

Each version of a question does have an ID (custom field) that could link (or exclude) them together. So for example "How to boil an egg?", whether it was in Video, Article or Slideshow format the ID would be the same.

From the research I've done, I haven't been able to find a solution. I have the view created but I haven't created any code as of yet to solve my problem.

#2238237

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello and thank you for contacting the Toolset support.

IMHO, because it is the same content with different formats, and because it has the same ID, it would be best to have one post type, with custom fields for the formats. For example, to have the Articles post type, and a custom field(or field group) for the Videos, and a custom field(of field group) for the Slideshows. This way, the search will return the article post, and you can display its fields(content, videos, slideshows). Does it make sense?

Otherwise, if you want to keep the 3 custom post types, you should enable search only for one of the post types(For example Articles) and disable it for the other post types(Videos & Slideshows). This way the search is performed against the Articles posts only. And you can display their related videos or slideshows in the search.

Please note that the above is about the default WordPress search. Which you can customize using an archive template.

If, on the other hand, you want this search section to be on one specific page, then you can create a view for it.

I assumed that you want to display only one type on the search, if you want to display also the other types(but exclude their related content), can you give me another example? If we search for "How to boil an egg?", what should we get? the Article, the video, or the slideshow?

#2239753

Thank you for you reply Jamal.

I understand where you are coming from and it makes sense. The reason why it was decided to go with three CPT is so we could have separation between them. As they also each have their own page with filters and grids (displaying a view). Thinking about it your solution would work fine but I've already made my bed.

The problem with setting the search to only one post type is say for example if "How to boil an egg?" didn't have an 'Article' and that was set as the CPT within search, it wouldn't be found.

I've been scouring the support forums and found a couple of threads that have provided me with a solution. Primarily this one: https://toolset.com/forums/topic/conditional-to-test-if-post-is-connected-via-relationship-or-similar-effect/

My theory is, if it is a child connection in anyway, don't show the post. I've set the relationships up so that the 'Document' (apologies if this caused confusion, it should be 'articles', I have mislabelled this within the website) is the only CPT that is never a child.

I've implemented it and it looks to me that it is doing what I need it to. I haven't done extensive testing, can you foresee any issues with the conditionals below?

[wpv-conditional if="( '[wpv-post-title item="@document-video.parent"]' eq '' ) AND ( '[wpv-post-title item="@document-slide.parent"]' eq '' ) AND ( '[wpv-post-title item="@related-video-or-slide.parent"]' eq '' )"]
  [wpv-post-body view_template="loop-item-in-support-loop"]
[/wpv-conditional]
#2239897

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

The conditions seems to check for parent posts in 3 relationships, if none exists then show the content template. This will work for parent posts, and for posts that does not have an Article/Document parent. Honestly, as long as it works as you would expect, just keep it.

However, this may give some inconsistencies. For example, if pagination, or a strict grid is applied, there maybe empty spots and less posts than a page is supposed to have(posts per page).

I'll remain at your disposal if you have any further questions.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.