niemand_0
Forum Replies Created
-
Forum: Plugins
In reply to: [Relevanssi - A Better Search] Excerpt only generated for first 10 postsOh, interesting!
The Relevanssi-generated excerpts are there for all posts, in the
post_excerpt
property.It isn’t there, however, in my
$post
variable:foreach($search_results->posts as $key => $result) { $post = get_post($result->ID); include('inc--search-preview.php'); }
Is it because I’m not in the WordPress “loop”? I tried that but I get a “have_posts() is not defined” error:
while($search_results->have_posts()) : $search_results->the_post(); include('inc--search-preview.php'); endwhile;
Am I missing something basic here? I haven’t built a query this way before so I’m not sure how to loop through it the “WordPress way”, rather than just doing a standard php
foreach
loop.Great idea with running the query directly on the database.
That turned out to not shed any light on the issue (other than that it returned the higher number as well), but using relevanssi_do_query in search.php (so I had the exact same code in both search.php and functions.php) and comparing the search results post by post did:
Turns out the query in functions.php returns posts with status “draft” and “pending review” as well as “published”. Adding
post_status = 'publish'
fixed it:global $query; $search_results = $query; $search_results->query_vars['s'] = 'wow'; $search_results->query_vars['posts_per_page'] = -1; $search_results->query_vars['post_status'] = 'publish'; $search_results->query_vars['offset'] = 0; relevanssi_do_query($search_results);
However, now I have two more issues/questions for you.
In search.php (using the same code as above), relevanssi excerpts are only be generated for the first 10 posts. I am using
get_the_excerpt()
.What is the best way to go about ordering posts with the same
relevance_score
? I would like posts with a more recent date to show up first.- This reply was modified 7 years, 4 months ago by niemand_0. Reason: cleaner code
Forum: Plugins
In reply to: [Relevanssi - A Better Search] FIltering specific visible custom fieldsDo a
var_dump($custom_fields)
to make sure the strings in your $unwanted_fields array are actually the field names being used in $custom_fields.You’ll see the result of the var_dump() on the Relevanssi admin page when you reindex.
- This reply was modified 7 years, 4 months ago by niemand_0.
Forum: Plugins
In reply to: [Relevanssi - A Better Search] ‘relevanssi_post_ok’ $post_ID returns NULLThank you! I knew it was probably me doing something funky.
Much appreciated.
Forum: Developing with WordPress
In reply to: ‘relevanssi_post_ok’ filter $post_ID returns NULLWill do, thank you!
Forum: Themes and Templates
In reply to: Check if password protected and password enteredHey @danieltj. Did you figure out a solution to this? I’m trying to figure out the exact same thing but can’t find anything short of checking the password cookie myself. It seems like a real oversight that
post_password_required()
doesn’t provide any sign of whether the user authenticated correctly.Forum: Plugins
In reply to: [Rich Reviews by Starfish] Stars should be partially colored inEntschuldigung, Ich habe alle meine Deutsch vergessen…Dank für in Englisch zu schreiben ??
It goes in a javascript file that you’re loading on the front end, within the document ready call. For example, I put the code in a file named site.js which I’m calling in the footer of my theme.
Forum: Plugins
In reply to: [Rich Reviews by Starfish] PHP Variable for total reviews on page?Perfect, thanks Charlie!
Forum: Plugins
In reply to: [Rich Reviews by Starfish] Stars should be partially colored inHere’s a solution for half stars in the meantime.
Note: This uses Font Awesome, which must be installed for this to work.
var ratingContainer = $('span[itemprop="aggregateRating"]'), starsContainer = $('.stars', ratingContainer), totalStars = Math.round(parseFloat($('.rating', ratingContainer).text()) * 2) / 2, wholeStars = Math.floor(totalStars), emptyStars = 5 - Math.ceil(totalStars); // empty the stars container element starsContainer.html(''); // add whole stars for (var i = 1; i <= wholeStars; i++) { starsContainer.append('<i class="fa fa-star" aria-hidden="true"></i>'); } // add a half star if applicable if (totalStars - wholeStars !== 0) { starsContainer.append('<i class="fa fa-star-half-o" aria-hidden="true"></i>'); } // add remaining empty stars for (var i = 1; i <= emptyStars; i++) { starsContainer.append('<i class="fa fa-star-o" aria-hidden="true"></i>'); } // [OPTIONAL] switch the individual reviews' stars to font awesome for consistency var indivReviews = { ratingContainer : null, totalStars : null }; $('.full-testimonial').each(function() { indivReviews.ratingContainer = $(this).find('.stars').html(''); indivReviews.totalStars = parseInt($(this).find('div[itemprop="reviewRating"] > span[itemprop="ratingValue"]').text()); for (var i = 1; i <= indivReviews.totalStars; i++) { indivReviews.ratingContainer.append('<i class="fa fa-star" aria-hidden="true"></i>'); } for (var i = 1; i <= (5 - indivReviews.totalStars); i++) { indivReviews.ratingContainer.append('<i class="fa fa-star-o" aria-hidden="true"></i>'); } });
Forum: Plugins
In reply to: [Rich Reviews by Starfish] PHP Variable for total reviews on page?Oh awesome, I didn’t realize I had access to the richReviews instance in my template files.
Ok, so I have that code in place but for some reason it’s returning with a count of zero reviews (even though I have three approved reviews on that page).
Here’s my code:
global $richReviews; $reviewData = $richReviews->db->get_average_rating('any', $post); $reviewCount = $reviewData['reviewsCount']; print_r($reviewData);
which prints out
Array ( [average] => 0 [reviewsCount] => 0 [category] => any )
Any thoughts?
Forum: Plugins
In reply to: [Rich Reviews by Starfish] Ajax in form option?You can also submit the form via ajax by using Malsup’s jQuery Form Plugin along with the jQuery validate code provided above.
$('.rr_review_form').validate({ rules : { input_stars : { selectStars : true } }, submitHandler : function(form) { // prepare the form for ajax submission $(form).ajaxForm({ success : function() {}, }); // submit the form via ajax $(form).ajaxSubmit(); // do your post submission tasks here, like hiding the form and displaying a success message. // [NOTE: this really should be in "success" callback parameter, but for some reason that won't fire.] // prevent the default submit return false; } });
Forum: Plugins
In reply to: [Rich Reviews by Starfish] Ajax="true" parameterYou can also submit the form via ajax by using Malsup’s jQuery Form Plugin along with the jQuery validate code provided above.
$('.rr_review_form').validate({ rules : { input_stars : { selectStars : true } }, submitHandler : function(form) { // prepare the form for ajax submission $(form).ajaxForm({ success : function() {}, }); // submit the form via ajax $(form).ajaxSubmit(); // do your post submission tasks here, like hiding the form and displaying a success message. // [NOTE: this really should be in "success" callback parameter, but for some reason that won't fire.] // prevent the default submit return false; } });
Forum: Plugins
In reply to: [Rich Reviews by Starfish] Form error and success messages to load via ajaxYou can also submit the form via ajax by using Malsup’s jQuery Form Plugin along with the jQuery validate code provided above.
$('.rr_review_form').validate({ rules : { input_stars : { selectStars : true } }, submitHandler : function(form) { // prepare the form for ajax submission $(form).ajaxForm({ success : function() {}, }); // submit the form via ajax $(form).ajaxSubmit(); // do your post submission tasks here, like hiding the form and displaying a success message. // [NOTE: this really should be in "success" callback parameter, but for some reason that won't fire.] // prevent the default submit return false; } });
Forum: Plugins
In reply to: [Rich Reviews by Starfish] PHP Variable for total reviews on page?After digging into this some I think I need some more guidance.
What function in particular is returning an array of the reviews? Do I have access to this function in my template file?
Forum: Plugins
In reply to: [Rich Reviews by Starfish] Form error and success messages to load via ajaxAjax functionality needs to be added to the core of this plugin, but in the meantime this code will cause validation errors to display without reloading the page.
The jQuery Validate plugin is needed for this code to work.
// add "required" attribute to the inputs and textareas that should be required $('.rr_review_form .rr_required + .rr_form_input > input, .rr_review_form .rr_required + .rr_form_input > textarea').attr('required', 'required'); // [IF USING STARS] add an input so stars can be validated $('.rr_stars_container').append('<input type="checkbox" name="input_stars" style="opacity: 0;">'); // [IF USING STARS] add a function to remove error when stars are selected $('.rr_stars_container').click(function() { if ($('.rr_stars_container').find('.glyphicon-star').length > 0) { $('input[name="input_stars"]').removeClass('error'); $('label#input_stars-error').hide(); } }); // [IF USING STARS] add a method to the validate plugin to check for a stars rating $.validator.addMethod("selectStars", function(value, element) { return $('.rr_stars_container').find('.glyphicon-star').length > 0; }, "Please rate this product."); // validate the form $('.rr_review_form').validate({ // [IF USING STARS] add a method to the validate plugin to check for a stars rating rules : { input_stars : { selectStars : true } } });