Exclude on post (ID-List) does not work
-
When I enter ids of posts I don’t want similar posts to be displayed, this does not work. The list of posts is still shown.
I use the template function to display the list.
-
Can you please post examples for this where you have it on your site.
What template function are you using?
Which option are you entering in the IDs?
I use
<?php if(function_exists('echo_ald_crp')) echo_ald_crp(); ?>in my template.
In the settings I entered the ids
18107,9972in the field “Exclude display of related posts on these posts / pages”. But when I open the post with the id 9972 a list of related posts is still displayed.I assume that it also displays on 18107?
Can you test one thing. Can you turn the automatic adding option on. i.e. the “Add Related Posts to”. And, see if it displays the posts on this ID?
I’m trying to see if for some reason the echo_ald_crp is breaking on your site.
I turned the automatic adding on for posts with an interesting result:
The normal posts showed the list twice now (one from the automatic adding and the other from the template function).
The excluded posts still showed the list once (the one from the template function).
So the auto-adding seems to look for the setting and the template function won’t.
Thanks that helps. I think there might be a bug in the way I initialise the
ald_crpfunction.Are you comfortable to edit the contextual-related-posts.php file and change line 89:
from
function ald_crp( $args = array() ) {to
function ald_crp( $args ) {No, this did not work. I changed the line, but the list is still there. It uses the large image and html-scales it down.
Gerobe. Let me look into this and try to debug the echo function.
Anything I can do to help?
I have a feeling that the arguments in the echo function are causing an issue and aren’t getting picked up by the ald_crp function.
Could try to omit the $args parameter completely from echo_ald_crp i.e.
function echo_ald_crp( ) { echo ald_crp(); }Changed the function but without success.
Gerobe, I finally figured this one out and apologies for making you try the various options.
The idea of the manual install till date has been to force the display of the posts overriding many conditions and so the “exclude on” only worked for the auto-insert.
You’ll notice in the code that it only kicks in on lines 518 and 519 in the plugin code file.
I realise this is not ideal because the echo function should respect all the settings. Could you please modify the echo function as follows and tell me if it works:
function echo_ald_crp( $args = array() ) { global $single, $post, $crp_settings; if ( ! in_the_loop() ) return; $exclude_on_post_ids = explode( ',', $crp_settings['exclude_on_post_ids'] ); if ( in_array( $post->ID, $exclude_on_post_ids ) ) return; // Exit without adding related posts parse_str( $crp_settings['exclude_on_post_types'], $exclude_on_post_types ); // Save post types in $exclude_on_post_types variable if ( in_array( $post->post_type, $exclude_on_post_types ) ) return $content; // Exit without adding related posts echo ald_crp( $args ); }Yes! It works with that code!
No related post displayed e.g. for my post id 9972. And they are still there on the other posts. Great! Thank you!
I marked the topic as resolved.
You’re welcome 🙂
The topic ‘Exclude on post (ID-List) does not work’ is closed to new replies.