Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Ajay

    (@ajay)

    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?

    Thread Starter gerobe

    (@gerobe)

    I use

    <?php if(function_exists('echo_ald_crp')) echo_ald_crp(); ?>

    in my template.

    In the settings I entered the ids 18107,9972 in 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.

    Plugin Author Ajay

    (@ajay)

    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.

    Thread Starter gerobe

    (@gerobe)

    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.

    Plugin Author Ajay

    (@ajay)

    Thanks that helps. I think there might be a bug in the way I initialise the ald_crp function.

    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 ) {

    Thread Starter gerobe

    (@gerobe)

    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.

    Plugin Author Ajay

    (@ajay)

    Gerobe. Let me look into this and try to debug the echo function.

    Thread Starter gerobe

    (@gerobe)

    Anything I can do to help?

    Plugin Author Ajay

    (@ajay)

    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();
    }

    Thread Starter gerobe

    (@gerobe)

    Changed the function but without success.

    Plugin Author Ajay

    (@ajay)

    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 );
    }
    Thread Starter gerobe

    (@gerobe)

    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.

    Plugin Author Ajay

    (@ajay)

    You’re welcome ??

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Exclude on post (ID-List) does not work’ is closed to new replies.