Skip Navigation

[Resolved] get a global variable for all views on one page

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to filter view by child post by taxonomy term using shortcode attribute and display it with different layout's visual editor cells

Solution:
To filter your child posts by category, you can use view's shortcode argument so you can use same view to filter multiple category and display it with different layout section.

You can find proposed solution with the following reply:
=> https://toolset.com/forums/topic/get-a-global-variable-for-all-views-on-one-page/#post-598017

Relevant Documentation:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

This support ticket is created 6 years, 11 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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: Asia/Kolkata (GMT+05:30)

This topic contains 14 replies, has 2 voices.

Last updated by Jim 6 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#597581

Jim

I have two custom post types: one is a journal and the other is a child of this journal that contains articles.

For every journal there is a page with a lot of views with articles from that journal, most of them based on categories.
So a view with headlines, a view with recomended etc...

In order to get the carticles that belong to a cetain journal I think I have to create nested views.

But now I wonder because I have to make a nested view for every one if there is an easier solution where I can store the Id of the parent Journal of that page and use that global variable for all the child views on that same page (layout).

I hope you understand the situation. Please let me know if there is such a solution or what else is the best way to create the child views.

Hope to hear froom you soon.
Thanks! Jim

#597622

Jim

Sorry, I should be more clear here.
My question does not relate to the parent main page. Because then it is easy; I can set the filter to "childres of the current post in the loop".

In my case, it is not the parent Journal page, but a kind of landingpage with information from the latest journal and articles from that latest journal.

Hope that makes more sense...
Thanks

#597677

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - I can better help you if you give me test case example with all required information and what will be your exact output to guide you in right direction.

Have you build parent child relationship with your custom post type using Types relationship?

#597691

Jim

Hi Minesh,
Thanks for getting back!

Yes, I have created the parent and child post types.
Have a look at this image:

hidden link

A - holds the title and image from the latest parent post type

1, 2 & 3 - are views. These are all articles (child posts from the parent post) filtered by a different category.

How can I create those (child) views without building a parent view for all three of them.
Is it possible to retreive the parent post id once and pass it on use it on to all three child views (by shortcode attribute for example)?

Hope this helps?

#597694

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

here my question is: are you displaying parent post single page and assigned layout to it?

#597697

Jim

No this is not the parent post single page (have a look at my second comment above: reply #597622)

This page not related to the parent post single page.

It is a special page (landingpage for members) with different kind information, and among that the latest edition of the journal with different lists of child articles from that latest journal.

#597698

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As I understand with this special landing page you want to display "latest journal" (only one post which is parent) and its associated categorized articles (childs) - correct?

so whats the definition of "latest journal"? is it the most latest parent post added?

#597699

Jim

Exactly Minesh, the latest (parent) post added.

#597700

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - great - thanks for all information.

Now, I would like to know how you display latest parent post information within layout? using what shortcode? Are you using view's to fetch latest parent post?

I'm understanding here you are using view's to fetch single latest parent post.

#597703

Jim

Yes, I was going to build a view to do that. Or is there a better way to fetch a single record?

#597705

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - so the best way is to use view to fetch parent latest post.

Now, to filter your child posts by category, you can use view's shortcode argument so you can use same view to filter multiple category and display it with different layout section.

More info:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

If you are not sure how to do it, you should just create view to fetch your parent post and display the parent information on layout and pass me the access details with problem URL where you would like to display the child posts articles.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#597754

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please check now: hidden link

I've created one parent view:
=> hidden link
Where:
- Added child view to parent view:

[wpv-view name="child_articles" term="overzichtsartikel"]      

- You can change the "overzichtsartikel" as per your desired taxonomy term slug.

One child view:
=> hidden link
Where:
- Child view is setup to filter by:

Taxonomy filter  
Select posts with taxonomy:
Rubrics slug in one of those set by the View shortcode attribute term
eg. [wpv-view name="view-name" term="xxxx"]

And

Post relationship filter
Select posts that are a children of the current post in the loop.
#597758

Jim

Alright!
Works very nice.

I was thinking: make one parent view, and a child view for every one you need.

You turned it around; as I see it, this way you create new parent views for every display I need right?

But that does mean that if I would like a different layout for the articles, then I do need to make a new child view?

#598017

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

No - I don't think you need to create more view's now. You can manage using two views (parent and child).

Please check here:
hidden link

We have two sections: "HEADLINES" and "HEADLINES 1"

So, you can pass with parent view - for which section you want to display the view. For example:

<h3 class="catlink">Headlines</h3>
[wpv-view name="latest_journal_edition_parent" section="headlines"]

<h3 class="catlink">Headlines 1</h3>
[wpv-view name="latest_journal_edition_parent" section="headlines1"]

And, in parent view's "loop output editor" section:
hidden link

You can check for which section you are displaying child posts (articles). For example:

  [wpv-conditional if="( '[wpv-attribute name='section']' eq 'headlines' )"]
		[wpv-view name="child_articles" term="overzichtsartikel"] 
      [/wpv-conditional]
      
      [wpv-conditional if="( '[wpv-attribute name='section']' eq 'headlines1' )"]
		[wpv-view name="child_articles" term="casuistiek"] 
      [/wpv-conditional]

So, as you can see - with section "headlines" - we are displaying articles which belongs to term "overzichtsartikel" and with section "headlines1" we are displaying articles belongs to term "casuistiek".

I hope above solution help you to resolve your issue. 🙂

#598053

Jim

Thanks very much Minesh!

Excellent help and support.
Appreciate it very much.

Have a great day!
Jim