I think there is some misconception about what we are doing. ??
Let’s dig into it.
We want that, when viewing a single post, the sidebar displays the posts from the category that we have defined in the custom field key (=CFK) _yoast_wpseo_primary_category
. The post we are viewing must have this CFK and also must be under the category defined in the CFK. This is our scope. Simple.
Test for the post test16
So, let’s look at the post Test16. This post:
– has the CFK _yoast_wpseo_primary_category
;
– has the CFV (custom field value) 9
that is the ID of the category violet
;
– is under the category violet
(and other categories, but this doesn’t affect our test).
When viewing this post in the front-end, the sidebar should display posts from the category 9
i.e. violet
.
Let’s look if this is true. Let’s go to the post test16
and we see that the posts retrieved are 5:
– test13
– test14
– test15
– test16
– test17
If we look at the categories of this posts, we see:
– test13 = blue, green, red, violet
– test14 = blue, green, red, violet
– test15 = blue, green, red, violet
– test16 = blue, green, red, violet
– test17 = blue, green, red, violet
So the plugin is working right. He has grabbed posts that are under the category violet
, which has the ID 9
.
Test for the post test17
Let’s look at the post Test17. This post:
– has the CFK _yoast_wpseo_primary_category
;
– has the CFV 6
that is the ID of the category red
;
– is under the category red
(and other categories, but this doesn’t affect our test).
When viewing this post in the front-end, the sidebar should display posts from the category 6
i.e. red
.
Let’s look if this is true. Let’s go to the post test17
and we see that the posts retrieved are 6 (notice the difference with the previous test where the posts retrieved were 5):
– test1
– test2
– test3
– test4
– test5
– test6
All of these posts are under the category red
which has ID 6
.
I hope that what I wrote is clear. ??