Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override star-placement with [kkstarratings] tag? #22

Closed
larskochhansen opened this issue Mar 23, 2017 · 5 comments
Closed

Override star-placement with [kkstarratings] tag? #22

larskochhansen opened this issue Mar 23, 2017 · 5 comments

Comments

@larskochhansen
Copy link

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

@larskochhansen larskochhansen changed the title Override star-placement with [kk XXX] tag? Override star-placement with [kkstarratings] tag? Mar 23, 2017
@kamalkhan
Copy link
Contributor

Have you tried disabling the star ratings in the admin for posts/pages and used the shortcode in a post/page editor manually?

@larskochhansen
Copy link
Author

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 👍

@kamalkhan
Copy link
Contributor

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?

@kamalkhan
Copy link
Contributor

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]');

@larskochhansen
Copy link
Author

larskochhansen commented Mar 25, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants