Code Monkey home page Code Monkey logo

Comments (5)

kamalkhan avatar kamalkhan commented on September 3, 2024

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

from kk-star-ratings.

larskochhansen avatar larskochhansen commented on September 3, 2024

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 👍

from kk-star-ratings.

kamalkhan avatar kamalkhan commented on September 3, 2024

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?

from kk-star-ratings.

kamalkhan avatar kamalkhan commented on September 3, 2024

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

from kk-star-ratings.

larskochhansen avatar larskochhansen commented on September 3, 2024

from kk-star-ratings.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.