Reviews for dynamic pages
-
I have a directory plugin that assigns pages to members dynamically. Meaning there is one page ID with a shortcode and then when you click on the member results, it brings up that page with their info.
I figured I can make the individual reviews work using categories, make a category for each member and then show them that way, but there are hundreds of members, so short of making a category for each one, not sure of what would be the best way to add unique reviews to each member’s info?
-
Since you are generating a page automatically for each member, and assuming this page is where you want the reviews to display, simply do this on the member page:
[site_reviews_form assign_to=post_id]
and
[site_reviews_summary assigned_to=post_id]
[site_reviews assigned_to=post_id]
This will assign submitted reviews to the member page when a review is submitted, and will only display reviews on that are assigned to the page.
yeah, that’s the thing. The post ID does not change. It’s always page-id-3718 for all members since the page is the same, only the member info changes dynamically. If I use the assigned_to=post_id in the shortcode, all the reviews show the same for everyone.
Do you have access to the user ID when using the shortcode? For example, are you using the shortcodes in your PHP template using
do_shortcode
?If yes, then you could do something like this:
/** * Create a category for the user if one does not already exist * @param array $defaults * @return array */ function glsr_filter_shortcode_defaults($defaults) { $term = $defaults['category']; if (!empty($term) && !term_exists($term, glsr()->taxonomy)) { $userId = filter_var(str_replace('user_', '', $term), FILTER_VALIDATE_INT); if ($user = get_user_by('id', $userId)) { require_once ABSPATH.'wp-admin/includes/taxonomy.php'; wp_create_term($term, glsr()->taxonomy); } } return $defaults; } add_filter('site-reviews/defaults/site-reviews', 'glsr_filter_shortcode_defaults'); add_filter('site-reviews/defaults/site-reviews-form', 'glsr_filter_shortcode_defaults'); add_filter('site-reviews/defaults/site-reviews-summary', 'glsr_filter_shortcode_defaults');
And then in your theme template, something like this:
$userId = ''; // You will need to have you user ID available here. $userTerm = 'user_'.$userId; echo do_shortcode('[site_reviews_form category='.$userTerm.']'); echo do_shortcode('[site_reviews_summary category='.$userTerm.']'); echo do_shortcode('[site_reviews category='.$userTerm.']');
For example, if the
$userId
is 13, then the category option on the shortcodes will use a value ofuser_13
, and if a category with this slug does not exist, it will automatically be created.-
This reply was modified 4 years, 9 months ago by
Gemini Labs.
There are no user id’s The Simple Business Directory lets us add members, so in this case it is a directory of doctors in our network. They dont have user accounts. We’re just displaying their information (profile) and letting patients go and review them. Sort of like zocdoc.
So their profile pages all have the same page ID and there are no user ids. There are “List ID” which is the category and “item ID” which is the doctor in that category.
(ex in screenshot: 3681 is the list ID for Dermatologists and 3681-1, 3681-2 & 3681-3 are the 3 doctors listed there)
Right now, I am usingdo_shortcode
but its showing the same rating for all doctors.
(https://pmd.almostdone.website/dashboard/ also See screenshot below)In that case, you can just remove the WordPress User check from the function. Instead you can use the list/item ID (i.e.
3681-1
):function glsr_filter_shortcode_defaults($defaults) { $prefix = 'item-'; $term = $defaults['category']; $isListItem = substr($term, 0, strlen($prefix)) === $prefix; if ($isListItem && !empty($term) && !term_exists($term, glsr()->taxonomy)) { require_once ABSPATH.'wp-admin/includes/taxonomy.php'; wp_create_term($term, glsr()->taxonomy); } return $defaults; }
$listItemId = ''; // You will need to have your list item ID available here. $category = 'item-'.$listItemId; echo do_shortcode('[site_reviews_form category='.$category.']'); echo do_shortcode('[site_reviews_summary category='.$category.']'); echo do_shortcode('[site_reviews category='.$category.']');
GREAT! Sorry for stupid questions, but
1. I assume the function goes into functions.php and the second part into the PHP page?
2.$listItemId = ''; // You will need to have your list item ID available here.
Item ID being 3681 or 3681-1? I have 19 categories and over a 100 listing id’s which will go up very rapidly. Is there a way to make this dynamic? If I leave it out, will it work?1. Yes
2. If you are assigning reviews to the the list (i.e. “Dermatologists”), then use the list ID. If you are assigning the reviews to the list items (i.e. “Sobel, Howard MD”), then you will need to use the list item ID.
Alternatively, the listing plugin you are using may provide a unique list item ID that you can use instead. The important thing is that the ID must be unique for each item (or list, if that’s what you are going for), and you will need to be able to access this ID in your PHP templates (both the list archive template, and the single view template).
The code will automatically create a new Site Reviews category (if one does not already exist) with the name/slug being the ID that you pass it.
If you need assistance with getting the list item ID in your templates, please contact the listing plugin support team.
I really appreciate you guys working with me on this. So I still cannot get it to work ??
The developer of the listing plugin came back with this: You can get the list item id by using
$list['qcpd_timelaps']. So, you should need to use $listItemId = $list['qcpd_timelaps'];
How would this alter the php code?
In that case, it would look like this:
$listItemId = $list['qcpd_timelaps']; $category = 'item-'.$listItemId; echo do_shortcode('[site_reviews_form category='.$category.']'); echo do_shortcode('[site_reviews_summary category='.$category.']'); echo do_shortcode('[site_reviews category='.$category.']');
If that is not working, please add this to the top of the code, refresh the webpage, and then copy/paste the result here (or send it using the “Contact Support” section of the Help page):
glsr_debug($list);
Still seeing the same results for everyone. Here is the results:
Array ( [qcpd_item_link] => https://sobelskin.com/ [qcpd_item_title] => Sobel, Howard MD [qcpd_item_subtitle] => Dermatologist [qcpd_item_phone] => 212-288-0060 [qcpd_item_email] => [qcpd_item_full_address] => 960a Park Avenue, New York, NY 10028, USA [qcpd_item_latitude] => 40.77791029999999 [qcpd_item_longitude] => -73.9595046 [qcpd_item_location] => New York, NY [qcpd_item_facebook] => [qcpd_item_twitter] => [qcpd_item_linkedin] => [qcpd_item_yelp] => [qcpd_item_business_hour] => [qcpd_fa_icon] => [qcpd_item_nofollow] => 1 [qcpd_item_newtab] => 1 [qcpd_item_img] => 3722 [qcpd_item_marker] => [qcpd_upvote_count] => 0 [qcpd_verified] => 0 [qcpd_entry_time] => 2020-02-19 14:52:54 [qcpd_timelaps] => 1580931277 [qcpd_paid] => [qcpd_is_bookmarked] => 0 [qcpd_description] => [qcpd_other_list] => [qcpd_tags] => Board Certified,Dermatologist, Dermatology [qcpd_ex_date] => )
I’ve improved it a little to give the generated categories more meaningful names.
/** * Put this in your theme's functions.php file * @param array $atts * @return array */ add_filter('site-reviews/shortcode/atts', function ($atts) { $prefix = 'item-'; $categorySlug = isset($atts['category']) ? $atts['category'] : ''; $isListItem = substr($categorySlug, 0, strlen($prefix)) === $prefix; if ($isListItem && strlen($categorySlug) > 5 && !term_exists($categorySlug, glsr()->taxonomy)) { require_once ABSPATH.'wp-admin/includes/taxonomy.php'; $categoryName = isset($atts['category_name']) ? $atts['category_name'] : $categorySlug; wp_insert_term($categoryName, glsr()->taxonomy, [ 'slug' => $categorySlug, ]); } return $atts; });
/** * This part goes in your template file * Make sure that the $list variable exists! */ $category = !empty($list['qcpd_timelaps']) ? 'item-'.$list['qcpd_timelaps'] : ''; $categoryName = !empty($list['qcpd_item_title']) ? sprintf('%s - %s', $list['qcpd_item_subtitle'], $list['qcpd_item_title']) : ''; // Remove the shortcode lines as needed... echo do_shortcode(sprintf('[site_reviews_form category="%s" category_name="%s"]', $category, $categoryName)); echo do_shortcode(sprintf('[site_reviews_summary category="%s" category_name="%s"]', $category, $categoryName)); echo do_shortcode(sprintf('[site_reviews category="%s" category_name="%s"]', $category, $categoryName));
Make sure that you are using the second code block on your archive and your single view pages. I can see that you are not using it on your single view page…
-
This reply was modified 4 years, 9 months ago by
Gemini Labs.
-
This reply was modified 4 years, 9 months ago by
Gemini Labs.
-
This reply was modified 4 years, 9 months ago by
Steven Stern (sterndata).
For some reason the last reply was flagged for review by a WordPress moderator.
Until then, here are the edited shortcode lines (the double quotes are important for the category_name part!):
echo do_shortcode(sprintf('[site_reviews_form category="%s" category_name="%s"]', $category, $categoryName)); echo do_shortcode(sprintf('[site_reviews_summary category="%s" category_name="%s"]', $category, $categoryName)); echo do_shortcode(sprintf('[site_reviews category="%s" category_name="%s"]', $category, $categoryName));
PERFECT!!! works as expected now ??
You may also wish to hide some of the summary fields on the archive page. To do this, you can use the
hide
shortcode option. Please see the “Site Reviews > Help > Shortcodes” page for help with this. -
This reply was modified 4 years, 9 months ago by
- The topic ‘Reviews for dynamic pages’ is closed to new replies.