0

Inside of an archive page I have multiple boxes. In those boxes I want to add a star rating, but I don't want to create a separate post for each of these boxes, I only want to make the boxes manually. All the star rating plugins want to fetch the post ID, but I don't want a post ID, I only want to apply the function in an isolated instance.

I also want multiple functions outputted in the same archive page (in this case, multiple star ratings on the same archive page).

Also, the post I am outputting in is not even a post or a page. In fact it is technically an archive page, which never actually displays any posts but instead various boxes inside the page, but not any posts.

One thing I tried was to specify a nonexistent post id like 99999999991, a number which would never become a real post id (since I won't write a billion blog posts). However, that didn't work, it just told me that that ID didn't exist.


Here is an image which shows some boxes with stars so you have a visual:

enter image description here What this page is, is an archive page. That is, it is the page the is visible when you visit the category URL like, mywebsite.com/category. Normally, I could display some posts in a loop for that category on the archive page. But here I am not doing that, I just put in some boxes into the category archives page.

Basically all the boxes which are just PHP/HTML boxes I want to apply a star rating, manually, or really I want to be able to apply any shortcode in an isolated instance. Rather than applying to a post.

As for the code, here is the code I used:

<?php echo do_shortcode('[ratings id="99999999991"]'); ?>

In this shortcode, is it for a star rating plugin, and the shortcode allows you to display the star rating for any post id using id="".

The shortcode doesn't work because it says, "no post with that ID". When I just try <?php echo do_shortcode('[ratings]'); ?> it displays the empty stars image, but it doesn't do anything when I try to click and actually if I try to rate one box all the boxes stars are affected at the same time and give the error.

I also tried using advanced custom fields (ACF plugin):

<?php the_field('star_rating'); ?>

What star_rating here is, is in advanced custom field I have the star ratings plugin for ACF and I created a custom star ratings advanced custom field and named it star_rating.

The ACF code doesn't work because it gives me an error since it isn't contained in any loop and isn't being applied to any specific post.

Both of these code examples will work, if used in a post. However, I want to use without and actual post, just by itself.


How can I apply wordpress functions which require to fetch a post ID, without actually having a post ID to specify for it (especially because I want multiple inside the page and it isn't really a page or a post but it's an archive page)?

  • 1
    Archive pages are intended to show posts. If there are no posts, it's not an archive page. Ratings are intended to rate something – a post, a page or a comment. What are these boxes you mention? What do they rate? – Max Yudin Mar 8 '17 at 10:54
  • What you are asking is not clear. Please provide some context with the CODE you tried or a graphic or both. – Fayaz Mar 8 '17 at 14:55
  • @MaxYudin It IS an archive page, and it CAN display posts, I just have the posts section commented out because there are no posts for that category (and I don't plan to ever make any). i.e. mywebsite.com/category is an archive page. If I have posts under that category, I can uncomment the loop and they will display under the archive page. It is indeed an archive page, despite containing no archives. A file cabinet is still a file cabinet even when it is empty. – user6686780 Mar 8 '17 at 17:02
  • @Fayaz I will post both. Give me a few minutes. – user6686780 Mar 8 '17 at 17:03
  • @Fayez: updated, hope that helps. – user6686780 Mar 8 '17 at 17:19
0

Your rating plugin will not work on custom HTML content (e.g. those boxes). Why? Because where will it save the rating related data? It must save the data somewhere, right?

Now, you don't want to add the rating in any post, that's fine. Your other option is to create a custom post type. You can do that using a plugin such as Custom Post Type UI.

WordPress allows you to create custom content (for example: Rating Box) known as custom post type, that can be used for any purpose.

Once you create a custom post type (using the plugin or your own custom CODE) and name it (for example) Rating Box, you'll be able to use ACF plugin to create a custom rating field for Rating Box. Then, use this custom post type to develop your custom archive page. Once you do that, you'll be able to rate them using the rating plugin (if that plugin supports custom post type - a standard plugin should support custom post type).

Another option will be to use the Settings API to save the data and show the rating on your custom HTML box using the values set from the Settings API or Options API.

  • This is one possibility, although certainly not an easy solution, would be better if I can find out how to save the data somewhere rather then code custom page types and custom loops and also try to integrate in a rating plugin into this custom loop which is a huge endeavor. Would be better just to somehow emulate the post individually like a few lines of code in functions.php, that is the kind of solution I am looking for if you have any advice on that which is a lot cleaner and less involved and won't take a week to develop just 5 minutes. – user6686780 Mar 9 '17 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.