We're merging with GenerateBlocks! Learn more here.

[Resolved] Apply action to one list only

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Apply action to one list only

  • This topic has 5 replies, 2 voices, and was last updated 3 years ago by Tom.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #19067
    Daniel
    Participant

    Hi there!

    I’m using the following code to use a custom image in my WP Show Posts list.

    Now I have created another list in WP Show Posts and I only want the code to be applied to one of the lists.

    How can I restrict the code to only the list I need?

    add_action( 'wpsp_before_title', 'tu_add_custom_meta' );
    
    	function tu_add_custom_meta() {
    		$image = get_field('logotipo');
    		$permalink = get_permalink();
    
    		if ( isset( $image ) && '' !== $image ) {
    			echo '<div class="av-logotipo"><a href="' . $permalink . '"><img src="' . $image . '"></a></div>';
    		}
    	}

    Thanks!
    Daniel

    #19093
    Tom
    Keymaster

    Hi there,

    Give this a shot:

    add_action( 'wpsp_before_title', function( $settings ) {
        if ( 123 === $settings['list_id'] ) {
            $image = get_field('logotipo');
            $permalink = get_permalink();
    
            if ( isset( $image ) && '' !== $image ) {
                echo '<div class="av-logotipo"><a href="' . $permalink . '"><img src="' . $image . '"></a></div>';
            }
        }
    } );

    Let me know 🙂

    #19107
    Daniel
    Participant

    Thanks for your reply Tom.

    I used the code you provided and changed list ID with the right one but it doesn´t work.
    The code I’m using is to display a custom image. With the updated code you gave me the image does not appear anymore. It’s like the code is not applied to the list anymore althought I changed the ID to the right one.

    #19135
    Tom
    Keymaster

    Sorry, my error there. Can you try the updated code?

    #19153
    Daniel
    Participant

    Now it works perfectly!

    Thank you very much.

    #19183
    Tom
    Keymaster

    You’re welcome 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.