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.
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
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:".
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.
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
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.
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.
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/