Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Changing rating to zero stars WordPress

  • SOLVED

Hello,

I'm using a restaurant theme and each menu item can have from 1-5 stars. I'd like to have an option with no stars at all.

Here is the code I could find in the template-menus.php file:

<?php
foreach($all_menu_arr as $key => $menu)
{
$small_image_url = '';
$image_thumb = array();

if(has_post_thumbnail($menu->ID, 'large'))
{
$image_id = get_post_thumbnail_id($menu->ID);
$image_thumb = wp_get_attachment_image_src($image_id, 'large', true);
}

if(isset($image_thumb[0]))
{
$small_image_url = get_stylesheet_directory_uri().'/timthumb.php?src='.$image_thumb[0].'&amp;h='.$pp_gallery_height.'&amp;w='.$pp_gallery_width.'&amp;zc=1';
}

$menu_price = get_post_meta($menu->ID, 'menu_price', true);
$menu_stars = get_post_meta($menu->ID, 'menu_stars', true);
if(empty($menu_stars))
{
$menu_stars = 5;
}

$yellow_stars = $menu_stars;
$blank_stars = 5 - $menu_stars
?>


And in the post-field.php file:

$postmetas =
array (
'menus' => array(

/*
Begin Slide Source custom fields
*/

array("section" => "Menu Options", "id" => "menu_price", "title" => "Price (ex. 100 USD):"),
array("section" => "Menu Stars", "id" => "menu_stars", "type" => "select", "title" => "Select how many stars you for this menu:",
"items" => array(
"5" => "5",
"4" => "4",
"3" => "3",
"2" => "2",
"1" => "1",
)),

/*
End Slide Source custom fields
*/
),
);


I tried a few things but without success...
Thanks for your help,
jonathan

Answers (2)

2012-05-28

Jurre Hanema answers:

@Agus: So then <em>every</em> menu item as zero stars. I don't think that's the intended behaviour.

Jonathan: try adding this line

"0" => "0"

immediately after

"1" => "1",

in post-field.php.

Also, since PHP's handling of strings containing "0" is notoriously weird, you will probably also have to change something in template-menus.php. I suggest you replace this line:

if(empty($menu_stars))

with this:

if($menu_stars === false)

Good luck!


Jonathan Surinx comments:

@jurre thanks, just tried it out but when I click on 0 from the admin it jumps back to 1 after refresh...


Jurre Hanema comments:

Well, from this code alone it's difficult to see where the problem is. Maybe it's caused by them using an empty()-like check somewhere. Instead of "0" => "0", can you try adding

"N" => "N"

? What happens then?

You can then also keep the if(empty($menu_stars)) as-is. If this doesn't work, I'll have to see the complete theme in order to figure out what the problem is.


Jonathan Surinx comments:

Yeah! It worked with "N" => "N".

And if(empty($menu_stars))
or if($menu_stars === false)

both solutions are working, many thanks :)


Jonathan Surinx comments:

Strange I can't vote for your questions...

I've got this message when I click on vote:

*****
3 groups of people are allowed to vote:
The true elite who've earned 1% of all winnings on the site.
The top monthly experts.
The admins of this site.

You can't vote!
*****

A WpQuestions bug?


Jurre Hanema comments:

You don't need to upvote my answer, but I think you need to click "Vote to award prize" just below your orginal question. Thanks!


Jonathan Surinx comments:

Very strange it didn't work before... now done great! :) Thanks again!

2012-05-28

Agus Setiawan answers:

how about removing :

$menu_stars = get_post_meta($menu->ID, 'menu_stars', true);
if(empty($menu_stars))
{
$menu_stars = 5;
}

$yellow_stars = $menu_stars;
$blank_stars = 5 - $menu_stars

on template-menus.php


Jonathan Surinx comments:

Thanks for your reply but no. I still want to use the stars for some items. But no all :/


Agus Setiawan comments:

i think, you must make a custom field like 'showstars' with value 0 or 1,

then you can make :

$stars = get_post_custom_values('showstars');

if ($stars==1){
$menu_stars = get_post_meta($menu->ID, 'menu_stars', true);
if(empty($menu_stars))
{
$menu_stars = 5;
}

$yellow_stars = $menu_stars;
$blank_stars = 5 - $menu_stars
}


Jonathan Surinx comments:

Hmm didn't work.

I just added those 2 lines:

if ($stars==1){
$menu_stars = get_post_meta($menu->ID, 'menu_stars', true);

But now the page isn't loading anymore... I switched it back.
Any other ideas?