Home › Forums › Product Support Forums › Related Posts Pro for WordPress Support › shortcode variables – exclude term
- This topic has 5 replies, 2 voices, and was last updated 9 years, 3 months ago by
Ernest Marcinko.
-
AuthorPosts
-
February 8, 2017 at 9:40 pm #11860
sank
Participanthi – need a shortcode variable to exclude terms per shortcode-call in WP.
example:
[wpdreams_rpp id=0 exclude=kod9]
[wpdreams_rpp id=0 exclude=hawtin]
[wpdreams_rpp id=0 exclude=dubstep]
February 10, 2017 at 2:07 am #11877sank
Participanthi there,
need an answer on this asap please – site is showing items that shouldn’t be there so need a way to remove them per-post, not a blanket “exclude”thanks!
February 10, 2017 at 10:24 am #11879Ernest Marcinko
KeymasterHi,
There is no such shortcode argument, so unfortunately that won’t work. A possible solution could be to make function on the ‘rpp_keywords’ filter, which is executed when the keywords are extracted.
Please note that this is not part of the plugin code and qualifies as a customization request, so I cannot guarantee it will work properly in every case.
I’ve tested the following code, use it in the functions.php file in your theme directory:
The $exceptions array contains the [post_ID => exception keywords array] pairs, you can add as many as you want with as many keywords as you need.
In the example this line:[php] ‘1’ => array(‘word1’, ‘word2’),[/php]
excludes word1 and word2 when the post ID equals 1.
Also, make sure to save the instane options to clear the related posts cache, or to disable cache temporarily while testing (on the Advanced Options panel).
February 10, 2017 at 5:44 pm #11890sank
Participanthmmm i see – yes it kind of works, but then removes any posts with that keyword.
is there a way to set the new code to exclude certain posts by ID instead of keyword?
example:$exceptions = array(
// Example: ‘[post ID]’ => array(‘[post ID]’),
‘9798’ => array(‘281’),
‘10422’ => array(‘5467’),
);so in essence i’m telling one post-type to exclude a certain page from the results…
(what would be ideal is in the actual plugin when the RPP box appears on every page in the admin, there could be an option to “Exclude this Post from Results!” )
I know this si all customization, if it requires more money i can pay…
thanks!
sFebruary 13, 2017 at 5:16 pm #11923sank
Participanthi,
is there a way to set the new code to exclude certain posts by ID instead of keyword?
example:$exceptions = array(
// Example: ‘[post ID]’ => array(‘[post ID]’),
‘9798’ => array(‘281’),
‘10422’ => array(‘5467’),
);February 16, 2017 at 10:55 am #11971Ernest Marcinko
KeymasterHi,
Well, without making a direct change to the plugin files it’s not possible. I will try to detail a possible change for you.
1. You will have to add an extra line to one of the core plugin files. I will make sure to add this line to the next release as well, so an update won’t break it. Open up the wp-content\plugins\related-posts-pro\includes\related_content.class.php file and scroll to line 82, which should be this:
[php]$args = wp_parse_args($args, $default_args);[/php]
2. Just under that line, place this:
[php]$args = apply_filters(‘rpp_args’, $args);[/php]
3. Then instead of the code I suggested earlier, use this one to exclude by IDs:
The only difference that in this case the IDs are simply listed as a string, not an array.
Let’s hope this works 🙂 -
AuthorPosts
- The forum ‘Related Posts Pro for WordPress Support’ is closed to new topics and replies.