Please or Register to create posts and topics.

Insert own shortcode at the end of each post

Page 1 of 2Next

Greetings,

For some reasons we need a rating system of posts. On othe rposts / pages we´re using a plugin to do the yob.

 

Because I´m a quite newbie, I´m asking me, if ots´possible to “inject” the shortcode of the rating form [rating_form id=”4″] at the end of each post.

And, to good to be true, how to do that?

The posts here in this support-forum about hooks are beyond my knowledge, I guess….

 

Regards, Andreas

Hello Andreas,

yes you have to use the available hooks for it. Here is an example code in which you have to add your voting/shortcode/whatever-logic you want to use:

function my_rating($authorID, $postID) {
  // Your logic here ...
}

add_action('asgarosforum_after_post_message', 'my_rating', 10, 2);

 

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

Great, so I did the following. And it works 🙂

 

// asgaros vote

function my_rating($authorID, $postID) {
echo do_shortcode(‘[rating_form id=”4″]‘);
}
add_action(‘asgarosforum_after_post_message’, ‘my_rating’, 10, 2);

Hm, now I´m confused, because on a vote on ONE post -> EVERY voting goes up.

Guess it´s not related to AsgarosFoum….but had anyone realized someting similar?

 

Thanks for a short hint, Andreas

You must pass the parameters $authorID, $postID …

Example:

function AsgarosForumRclAuthorLike($author_id, $author_posts) {
  global $active_addons;
  if(!$active_addons['rating-system']) return false;
  $object_id = $author_posts;
  $recall_rating_like = '<div class="rating-post rating-header">'.rcl_get_html_post_rating($object_id,'forum-page',$author_id).'</div>';
  return $recall_rating_like;
}

This is only an example!

 

 

 

Hi Yworld,

thanks for your reply. But I´ve to confess, that I don´t understand, what you´re doing in your example (sorry, I´m a beginner related to php…).

Let´s see, if I´ve undestood you:

AIM: I want to insert a voing shortcode under each post within a thread, done by a shortcode like “[rating_form id=”4″]”

 

So I´ve to pass the variables on each post, understood. But how to deal with your example in the post before?

The line “function my_rating($authorID, $postID)” should generate a reating for let´s say Author1 and Post23, so it should be unique? But you´re right, that doesn´t work.

May your able to explain the lines you´ve posted or give me another tipp how to work in the “[rating_form id=”4″]” shortcode (I´ve searched a lot of time in the meanwhile with google and within this and the WP forums, without success…)?

 

Thanks again,

Andreas

what plugin are you using?

Hm, So I´ve thought about

 

function my_rating($authorID, $postID) {
echo do_shortcode('[rating_form id="4" post_id="postID"]');
 }
add_action('asgarosforum_after_post_message', 'my_rating', 10, 2);

to set the post ID. The rating form used https://ratingform.net/documentation/  has some instructions for bbPress:

How to use a Rating Form inside bbPress Replies?

You just need to insert the rating form shortcode after or before a reply content, Rating Form will detect automatically the current comment id.
Example code ( Change { } to [ ] ):

If you are getting the same rating result on all replies. You can try to use a function of bbPress that gets the current reply ID. Adjust the shortcode as followed:

Now we are telling this Rating Form with id 1 that the parent (post) ID is the current reply ID.
Because reply is a (custom) post type which is stored in the same place as any other post types (like post), so we are voting a unique post ID.

Rating System (Last updated: 1 year ago) This plugin does not suit. Need with api

 

I also thought about WP Ulike https://wordpress.org/plugins/wp-ulike/

Or any other you´ll suggest 🙂

 

 

Page 1 of 2Next