Skip Navigation

[Resolved] Showing Contents & Hiding Contents in Similar Views

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.

Our next available supporter will start replying to tickets in about 3.92 hours from now. Thank you for your understanding.

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 22 replies, has 2 voices.

Last updated by Minesh 1 year, 11 months ago.

Assisted by: Minesh.

Author
Posts
#2527499
21146444-973D-4A80-AE06-77C5BCE62431.png
B7665824-A1A6-49CC-8EA3-CC7C9F86762F.png
EDCEF7F1-5FB8-4A0A-9507-FDC9CE73F44E.png
C4BBC9D9-9003-4D77-AB68-AC5FC4A7C83F.png
58B4A656-72CA-4F22-ABAA-B681A620EFCF.png

EXAMPLE 1 PUBLIC POST:
I’ve created this post
hidden link

I’ve selected the following:
- Category:
Article
N.B. There’s Articles SN that will be chosen later on in the other post.

- Subject:
— 01. العلاقة مع الله >>
—— 01.01. الخلاص >>
——— A. إسترداد كل شيء
N.B. This is a common Subject for both posts I’m applying the example on.

- Sections:
Public
N.B. There’s another taxonomy called SN with its Children that will be chosen in the other example.

The above post should appear in the Public Articles & Sermons’ output, when the user clicks on the subject it should bring this post as output.
hidden link

EXAMPLE 2 SN POST:
I’ve created this post
hidden link

I’ve selected the following:
- Category:
SN >>
Article مقالات - SN

- Subject:
— 01. العلاقة مع الله >>
—— 01.01. الخلاص >>
——— A. إسترداد كل شيء
N.B. This is a common Subject for both posts I’m applying the example on.

- Sections:
Social Network شبكة التواصل
N.B. This is abbreviation of SN.

This post EXAMPLE 2 should appear in the SN Articles & Sermons’ output, when the user clicks on the subject it should bring this post as output.
hidden link

As general: the links of the Subjects shows same views but the output is the difference.
Same views in the Public Articles & Sermons page & the SN Articles & Sermons page main page … both are showing Subjects for these subjects is generalized allover the site … but the Output (posts) should be different….showing or hiding the contents in the output should be filtering out (hiding) or showing the contents according to the selection not of the Subjects but of the SN selection or deselection when it’s belonging to SN it’ll be chosen in both
Category “SN”
+
Sections “Social Netowrk”
If it’s public the above won’t be selected….which means they’re public.
Again don’t worry about logged in or logged out.
—————————-
Example that I succeeded to apply is the new updates that shows new added posts in these two pages to help the users find them quickly by date:
hidden link
This shows the new added posts for public (Doesn’t contain SN)

While the following one shows only the ones for SN
hidden link
It doesn’t show any public ones but shows ONLY for SN & its children SN Articles, SN Sermons, Team.

I want the same happens in the Subjects page’s OUTPUT … the posts to be shown same way….same Subjects but different outputs.

#2527549

Minesh
Supporter

Languages: English (English )

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

So lets first talk about: EXAMPLE 1 PUBLIC POST:
This post EXAMPLE 2 should appear in the SN Articles & Sermons’ output, when the user clicks on the subject it should bring this post as output.
hidden link
==>
When I visit the above page and click on the "--- A. استرداد كل شىْ" as you can see with the following screenshot:
- hidden link

I can see the "public post not for sn" at top of the list:
- hidden link

So it is expected and working - right?

#2527553

Right this is because I didn’t select any SN for this post….And you’ve been able to hide the other one which is for SN.
Yes.

#2527789

Minesh
Supporter

Languages: English (English )

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

For "EXAMPLE 2 SN POST:"
This post EXAMPLE 2 should appear in the SN Articles & Sermons’ output, when the user clicks on the subject it should bring this post as output.
hidden link
==>
When I click on subject "——— A. إسترداد كل شيء" from the above SN page strangely something else in involved it seems queries are hijacked by any other plugin or theme as I simply can hook the "pre_get_posts".

This is not true for the"EXAMPLE 1 PUBLIC POST:" I can see the "pre_get_post" hook is fired with this but not with the "EXAMPLE 2 SN POST:".

#2528117
4A6D1BBA-2AB3-4A63-B994-14F2A7BDD072.png

It’s working & shows the two posts that I’ve created…it should show only the SN one.\

Also in the other main page the same output it shows both posts.

I think the way it should be done is the Archive should be different or embedding a code in the Posts view to prevent or allow the ones with SN or without.

#2528323

Minesh
Supporter

Languages: English (English )

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

Basically you have to hook in the "pre_get_posts" hook for example to only display "SN" posts here is the example code:

function func_exlcue_sn_posts_archive( $query ) {
    
    if( is_admin() ) return;
    
  
   if(is_tax('subject') and $query->is_main_query() ) {
     
       $result_post_ids = get_posts(
    array(
        'post_type' => 'post',
        'numberposts' => -1,
        'fields'=>"ids",
        'tax_query' => array(
        	array(
            	'taxonomy' => 'section',
            	'field' => 'term_id',
            	'terms' => array(80), // for the public site term ID
           		'include_children'=> true,
            	'operator'=> 'IN'
        	),
           array(
            	'taxonomy' => 'subject',
            	'field' => 'term_id',
            	'terms' => array($query->queried_object_id),
           		'include_children'=> true,
            	'operator'=> 'IN'
        	),
       
       )
    )
);
 
     
     $query->set( 'post__not_in', $result_post_ids );
 
      
   }
}
add_action( 'pre_get_posts', 'func_exlcue_sn_posts_archive',9999);

Somehow you site using heavy caching and I could not able to hook in "pre_get_posts" properly. The same way you have to adjust the above code to NOT display SN posts with the following URL: hidden link

You can adjust the above code as required.

#2528449

Okay…where shall I add this code? What is the variable exactly that should be changed?

What about the same page for output is coming out when I click on any subject or child of subject…so how can I make the two main pages give different outputs?
Thanks.

#2528461

Minesh
Supporter

Languages: English (English )

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

What about the same page for output is coming out when I click on any subject or child of subject…so how can I make the two main pages give different outputs?
==>
As shared you re using taxonomy archive and there is no way for me to override the "pre_get_posts" hook seems your thrid-party plugin or theme hijacks the queries and even more I see your site is using cache so even I made a change it does not reflect soon.

You can decide your own logic how you want to create two different archives based on what action trigger as your site structure is simply really complex and you have number of nested views.

You can find more examples here how to use pre_get_posts:
- https://wordpress.stackexchange.com/questions/35196/theres-a-way-to-use-query-settax-query-in-pre-get-posts-filter

You can add the "pre_get_psots" hook to your theme's functions.php file or to the "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

If you do not know how to adjust the PHP code please check with any of our certified partners as supporting such custom code is beyond the scope of our support policy. You can hire any certified partner for your such custom edits:
=> https://toolset.com/contractors/