Forum Replies Created
-
AuthorPosts
-
humblehumans86
ParticipantErnest you continue to provide amazing customer support for this product. Worked like a charm just had to
update the Custom Post Type name ‘product_cpt’ and add the return for the results. behold ….p.s. Good to mark resolved on all fronts! Thank you again.
add_filter('asp_results', 'asp_search_result_interchange', 10, 1); function asp_search_result_interchange($results) { // Loop through results foreach ( $results as $k => &$r ) { // Check if this is a product if ( isset($r->post_type) && $r->post_type == 'product_cpt' ) { // Get Taxonomy Term IDs based on Post ID of Search Result $term_ids = wp_get_post_terms( $r->id, 'interchange_ct', array( 'fields' => 'ids' )); // Get Taxonomy Term objects based on applicable Term IDs $terms = get_terms( 'interchange_ct', array( 'include' => $term_ids, 'orderby' => 'term_order', 'order' => 'ASC', 'hide_empty' => true ) ); // Create array to store unique Term Names $list = array(); // Add Term Name to list if unique foreach ( $terms as $term ) { if ($term->parent > 0 && $term->name !==$product_name && !in_array($term->name, $list) ) { $list[] = esc_html( $term->name ); } } // Add the imploded list of terms to the results content if (!empty($list)) { $r->content = implode( ', ', $list ) . '<br>' . $r->content; } } } return $results; }humblehumans86
ParticipantErnest ,
This might be a bit of a stretch but its worth an ask. In any event appreciate all the help thus far.
Our site has two types of searches, one in the header powered by ASP and an inline page search powered by a combination of possbile of input queries. As it relates to the original task of displaying Taxonomy Terms of said search results I was able to replicate the behavior on both. So for that alone thank you again!
Furthermore I was able to implement a hierarchical display of taxonomy terms relative to each search result but with a bit of a performance loss. So instead I altered my ask and was hoping you could point me in the right direction to replicate with ASP.
Essentially I have a function in my functions.php file that accepted two parameters, a post ID and Name (though the function could determine Name, I just had value stored when I was calling function). Based on that it generates the following taxonomy terms but prevents terms from displaying based on the following criteria.
A. Taxonomy Term is the same value as the Post Title
B. Taxonomy Term is a Parent Term
c. Taxonomy Term is already being displayed and within our Term arrayHow would you recommend achieving similar result with ASP as this function only addresses our inline page search? For instance assuming I need the ‘asp_results” filter but unable to determine exactly what is being passed off in $results. Below is the function i’m using to accomplish this task with my non-ASP search.
function search_result_interchange($product_name, $product_id) { // Get Taxonomy Term IDs based on Post ID of Search Result $term_ids = wp_get_post_terms( $product_id, 'interchange_ct', array( 'fields' => 'ids', ) ); // Get Taxonomy Term objects based on applicable Term IDs $terms = get_terms( 'interchange_ct', array( 'include' => $term_ids, 'orderby' => 'term_order', 'order' => 'ASC', 'hide_empty' => true ) ); // Create array to store unique Term Names $list = array(); // Add Term Name to list if unique foreach ( $terms as $term ) { if ($term->parent > 0 && $term->name !==$product_name && !in_array($term->name, $list) ) { $list[] = esc_html( $term->name ); } } // If no unique Terms Names are found display Post Name if (!empty($list)) { echo implode( ', ', $list ); } else { echo $product_name; } }-
This reply was modified 6 years ago by
humblehumans86.
humblehumans86
ParticipantHierarchal sorting honestly is the most important element ignoring the other two requests. To make use of the internal functions would you wrap inside a hook in function.php?-
This reply was modified 6 years ago by
humblehumans86.
humblehumans86
Participantimg for reference. The table on the left has a section called “Interchanges”. Basically each interchange is a taxonomy of the produt listed at the top. Parent and Child denoting a Manufacture name and their corresponding Part Number for this specific Part Number listed at the top. So Ideally taxonomies are listed as Parent1 – Child, Parent -Child, etc opposed too Parent, Parent, Parent, Child, Child, Child
humblehumans86
ParticipantNo worries, everything else has been so easy time to roll up the sleeves!
Not only do I need to exclude Parent terms that have no Children, I need to exclude the Children term of three specific parent IDs .
Grouping Parents and Children terms isn’t possible either right?
Tried theorderby='parent' propertywithout successAssuming all three of these needs will have to be accomplished with a custom hook.
Here’s my current setting
{__tax_interchange_ct count=20 separator=', ' orderby='parent' order='ASC' exclude='21172,21174,73200' }humblehumans86
ParticipantPerfect! looking at the documentation i think it’s possbile but before I go down that rabbit hole off hand do you know if its possible to only display Parent Term and Child if a Child exists? Omitting parents that have no children?
humblehumans86
ParticipantRated and Commented, thanks again!
I got one more question regarding another topic, should I post as a new thread?
Question is whether or not its possbile to display associated taxonomies with the title as results rather than an image or description.
humblehumans86
ParticipantWell I stand corrected. Force Insensitivity setting did the trick despite the changes to DB collation we have on that table. You sir are are awesome, THANK YOU ten fold.
humblehumans86
ParticipantUnfortunately we have to force case sensitivity on the DB table that stores the custom field we are searching. My knucklehead clients use the same value in upper and lower case to denote a dimensions for a sister custom field. No way around it, been a huge pain to program around. A filter is perfect, thank you for the quick response will implement now.
-
This reply was modified 6 years ago by
-
AuthorPosts