Closed larskochhansen closed 7 years ago
Have you tried disabling the star ratings in the admin for posts/pages and used the shortcode in a post/page editor manually?
Hi Kamal, Yes. It works fine when disabling the automatic insertion. Its just that I have about 150 posts on my blog, and I really love that the stars are inserted automatically. But all the new posts I really would like to be able to decide where to put it.
If its a lot of work then I'll just have to go through it manually 👍
You could append/prepend the shortcode into all the posts programatically using php only the one time. Are you able to figure that out on your own? or do you need help in that?
To insert the shortcode programatically use the below function in your theme folder -> functions.php file. NOTE: After placing this code in the functions.php file, refresh your website in the browser only once! After the refresh, remember to remove the code or uncomment the function call at the end. If you do not do this, the shortcode will be inserted each time you refresh your website in the browser.
function addShortcodeString($postType, $shortcode = '[kkstarratings]') {
foreach (get_posts(['numberposts' => -1, 'post_type' => $postType]) as $post) {
$post->post_content = $shortcode . $post->post_content;
wp_update_post($post);
}
}
// Call the function.
// 1. Pass a post type, e.g. 'post' or 'page', ...
// 2. Pass a shortcode (optional, defaults to '[kkstarratings]')
addShortcodeString('post', '[kkstarratings]');
Thanks a lot Really appreciate it 😁
/Lars
Den 25. mar. 2017 kl. 01.41 skrev Kamal Khan notifications@github.com:
To insert the shortcode programatically use the below function in your theme folder -> functions.php file. NOTE: After placing this code in the functions.php file, refresh your website in the browser only once! After the refresh, remember to remove the code or uncomment the function call at the end. If you do not do this, the shortcode will be inserted each time you refresh your website in the browser.
function addShortcodeString($postType, $shortcode = '[kkstarratings]') { foreach (get_posts(['numberposts' => -1, 'post_type' => $postType]) as $post) { $post->post_content = $shortcode . $post->post_content; wp_update_post($post); } } // Call the function. // 1. Pass a post type, e.g. 'post' or 'page', ... // 2. Pass a shortcode (optional, defaults to '[kkstarratings]') addShortcodeString('post', '[kkstarratings]'); — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
Would it be possible to allow users to use the [kkstarratings] code to override the automatic placement in a post? I really love the plugin and like that you may exclude categories. As I have just begun using the plugin it's nice that all posts now have the ability to be "rated". However, I really would love the option to insert the "ratings" on specific places in some posts with the [kkstarratings] tag. Would it be possible to change the code so that if a [kkstarratings] is in the text the automatic insertion (chosen in settings) would be left out?
Does it make sense?
I really hope that it is possible... :-) Best wishes Lars