• Resolved claudien

    (@claudien)


    It’s more like a suggestion then a reel bug , but it would be very usefull for us if we were able to pass the post id through the shortcode. Doing so, we would be abble to use the shortcode on list as well ?? you could only change get_the_id() by something like $post_id = ! empty( $post_id ) ? $post_id : get_the_ID(); and the shortcode would become [oacsspl id=$post_id ] in our code.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author oacstudio

    (@oacstudio)

    Hi @claudien

    It’s more like a suggestion then a reel bug , but it would be very usefull for us if we were able to pass the post id through the shortcode. Doing so, we would be abble to use the shortcode on list as well ?? you could only change get_the_id() by something like $post_id = ! empty( $post_id ) ? $post_id : get_the_ID();

    I think I see what you mean in terms of coding, but what is your goal here? ??

    You want to be able to show likes of any post via shortcode anywhere? Like so:

    1) [oacsspl] = show like button of current post.
    2) [oacsspl id=13] = show like button of post with ID 13.

    Correct?

    Kind regards,
    Anna

    • This reply was modified 2 years, 5 months ago by oacstudio.
    Thread Starter claudien

    (@claudien)

    Exactly, it would allow us to put your shortcode in a post list querying each single post id. Currently, if I put your shortcode on a post listing page, the get_the_ID() take the page ID of the listing instead of the single post item. So I would do something like:

    foreach ($posts as $post) {
    [oacsspl id=$post->ID]
    }

    Thank you !

    Hi,

    I’ve met the same problem where I wanted to use the class SolidPostLikesPublic in a page calling other posts and I wanted to display the button but for some posts.
    I was able to do it with a little modification in the function oacs_spl_display_like_button in views/SolidPostLikesPublic.php where the $post_id is actually taken in account in the 2 lines concerned if defined.
    Like this :

    if ($is_comment == 1) {
     $post_id       = ! empty( $post_id ) ? $post_id : get_comment_ID();
    } else {
     $post_id          = ! empty( $post_id ) ? $post_id : get_the_ID();
    }

    What claudien wants I think is to be able to do so in the shortcode with a parameter
    like so : [oacsspl id=13] where then the function is calling oacs_spl_display_like_shortcode to take into account this id and do :
    echo wp_kses_post($this->oacs_spl_display_like_button($post_id, 0)); and finally fall back to my code in order to display the like buttton for this post id.

    • This reply was modified 2 years, 5 months ago by clnjo.
    Plugin Author oacstudio

    (@oacstudio)

    Hi again,

    @claudien – understood. Thanks for the added details.

    @clnjo – thanks a lot for the input. I will test the implementation and see if there is anything else that needs attention.

    Kind regards,

    Plugin Author oacstudio

    (@oacstudio)

    Hi @claudien, @clnjo

    Version 1.0.2 is available.

    You can now use [oacsspl post_id=123] to show post likes of post with the ID = 123. The Fallback post_id value is the current post ID.

    Let me know if anything does not work as expected.

    Thread Starter claudien

    (@claudien)

    Thank you ??

    • This reply was modified 2 years, 5 months ago by claudien.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Passing id trough shortcode’ is closed to new replies.