• Resolved luciver

    (@luciver)


    @yasr-shortcode-functions.php

    add_shortcode (‘yasr_visitor_votes_readonly’, ‘yasr_visitor_votes_readonly_callback’);
    function yasr_visitor_votes_readonly_callback ($atts) {
    $shortcode_html = NULL;
    $a = shortcode_atts( array(
    ‘id’ => get_the_ID(),
    ), $atts );

    $post_id = $a[‘id’];
    //$post_id = get_the_ID();
    $votes=yasr_get_visitor_votes($post_id);

    https://www.ads-software.com/plugins/yet-another-stars-rating/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter luciver

    (@luciver)

    Oups maybe a pro feature, If it, I delete.

    Plugin Contributor dudo

    (@dudo)

    Hi luciver, thank you for using YASR!

    not sure what are you trying to do here?
    Seems like you want to pass the post id as a shortcode argument, but it will simply get overwritten by the get_the_ID().

    Further, there is no need at all to pass post id as argument cause the function get the post id itself (with the line you comment out)

    Have I missed anything?

    Best,
    Dario

    Thread Starter luciver

    (@luciver)

    On page that have a list of post, the id must be pass to work, otherwise, we have the rank of the page but not for each post. Just needed on sensei than not allow ranking without a product…
    So I had changed to pass the id.

    Other thing, you havent implement Enabling Rich Snippets or it s a pro feature?
    I m looking for it in [yasr_visitor_votes_readonly]

    Tks

    Plugin Contributor dudo

    (@dudo)

    Ok, but why change the shortcode atts? You can pass the post_id to yasr_get_visitor_votes simply using

    $post_id = get_the_ID();
    $votes=yasr_get_visitor_votes($post_id);

    $a[‘id’] and $post_id are just the same thing

    Rich snippets are avaible in free version too. They will appear if you use the overall rating or the yasr_visitor_votes shortcode: you can see it on your post/page where you use that shortcode.

    Using that in the readonly one is a non sense, because that function have to print the stars and stars only, to integrate it in a template.

    The rich snippet instad add a text, read here https://www.ads-software.com/support/topic/remove-sentence-at-the-end-of-post?replies=11

    Thread Starter luciver

    (@luciver)

    Tks I see it ??

    For the parameter, it s the same, but in the loop-course, it seems that the $post_id is not set. It comes from an other part
    $posts_array = $woothemes_sensei->post_types->course->course_query( $amount, $query_type, $course_includes, $course_excludes );
    <?php foreach ($posts_array as $post_item){
    array_push( $course_excludes, $post_item->ID );
    $post_id = absint( $post_item->ID );

    If I remove the parameter, it does not work.

    Ok all good, just add a way to reset vote.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘shortcode with post_id solved’ is closed to new replies.