Insert own shortcode at the end of each post
Quote from Andreas on September 12, 2017, 4:27 pmGreetings,
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
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
Quote from Asgaros on September 13, 2017, 8:27 pmHello 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);
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);
Quote from Andreas on September 14, 2017, 9:37 amGreat, 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);
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);
Quote from Andreas on September 14, 2017, 3:55 pmHm, 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
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
Quote from Yworld on September 14, 2017, 5:49 pmYou 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!
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!
Quote from Andreas on September 15, 2017, 9:36 amHi 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
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
Quote from Andreas on September 15, 2017, 10:31 amHm, 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 [ ] ):
1234 function bbp_rating_form($content){return $content . do_shortcode(‘{rating_form id=”1″}’);}add_filter(‘bbp_get_reply_content’, ‘bbp_rating_form’);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:
1 {rating_form id=“1” post_id=“‘ . bbp_get_reply_id() . ‘”}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.
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 [ ] ):
1234 function bbp_rating_form($content){return $content . do_shortcode(‘{rating_form id=”1″}’);}add_filter(‘bbp_get_reply_content’, ‘bbp_rating_form’);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:
1 {rating_form id=“1” post_id=“‘ . bbp_get_reply_id() . ‘”}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.
Quote from Yworld on September 15, 2017, 10:38 amRating System (Last updated: 1 year ago) This plugin does not suit. Need with api
Rating System (Last updated: 1 year ago) This plugin does not suit. Need with api
Quote from Andreas on September 15, 2017, 10:51 amI also thought about WP Ulike https://wordpress.org/plugins/wp-ulike/
Or any other you´ll suggest 🙂
I also thought about WP Ulike https://wordpress.org/plugins/wp-ulike/
Or any other you´ll suggest 🙂