Category Name Filter Not Working

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Category Name Filter Not Working

This topic contains 14 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 6 years, 8 months ago.

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #6610
    ar
    ar
    Participant

    Hi there,
    Lovely plugin.
    I’m having some trouble getting the catetory id-> name filter to work. I’ve copied the code from the knowledge base a few times (to make sure I copied all correctly) with no success.

    I’m using WP 4.3.1
    Searching custom post types
    pulling data from Advanced Custom Fields
    The post type also uses it’s own taxonomy.

    I’ve installed the updated plugin and I’ve tried disabling all plugins (except for Advanced Custom Fields which I need for the search).

    I was able to get the acf image filter to work, so I’m not sure where I’ve gone wrong.

    I realize it may be impossible to diagnose without access to live site, but unfortunately I’m working on a local version. If necessary, I can try to install the site on my own server, etc. But thought I’d start here.

    Many Thanks for your help.

    • This topic was modified 6 years, 8 months ago by ar ar.
    #6611
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    I think the problem here might be that you are using a custom taxonomy.

    I suppose you are talking about this example: https://wp-dreams.com/knowledge-base/showing-the-category-titles-in-the-result-title/

    This only works with post categories, because for other taxonomy terms a different wordpress function is used. I’ve made a quick modification, that should get the terms of the specified taxonomy:

    
    add_filter( 'asp_pagepost_results', 'asp_add_term_titles', 1, 1 );
     
    function asp_add_term_titles( $pageposts ) {
      foreach ($pageposts as $k=>$v) {
     
        // Edit this to the taxonomy you are using
        $taxonomy = "mytaxonomy";
     
        // Get the taxonomy terms
        $post_terms = wp_get_post_terms( $pageposts[$k]->id, $taxonomy );
        $terms = "";
     
        // Concatenate category names to the $cats variable
        foreach($post_terms as $c){
            $term = get_term( $c, $taxonomy );
            $terms = " ".$term->name;
        }                
     
        // Modify the post title
        $pageposts[$k]->title  .= " ".$terms;
      }
     
      return $pageposts;
    }
    

    Don’t forget to change the $taxonomy variable to the taxonomy you are using with the custom post type.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #6619
    ar
    ar
    Participant

    Firstly, thank you so much for the speedy reply!

    I tried the code above using the taxonomy single name, the plural name and the slug without success.

    code is below:

    
    add_filter( 'asp_pagepost_results', 'asp_add_term_titles', 1, 1 );
     
    function asp_add_term_titles( $pageposts ) {
      foreach ($pageposts as $k=>$v) {
     
        // Edit this to the taxonomy you are using
        $taxonomy = "Design";
     
        // Get the taxonomy terms
        $post_terms = wp_get_post_terms( $pageposts[$k]->id, $taxonomy );
        $terms = "";
     
        // Concatenate category names to the $cats variable
        foreach($post_terms as $c){
            $term = get_term( $c, $taxonomy );
            $terms = " ".$term->name;
        }                
     
        // Modify the post title
        $pageposts[$k]->title  .= " ".$terms;
      }
     
      return $pageposts;
    }
    

    any thoughts on what else I might try?

    Many thanks for your help,
    Anne

    #6625
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    I think the $taxonomy is not correct. Try:

    $taxonomy = “design”;

    in lower case. I believe it expects the taxonomy slug, not the actual name, which I suppose is the lower case version.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #6723
    ar
    ar
    Participant

    Hi there,

    Thanks again for the help. I’ve tried the taxonomy slug name and the proper name (plural and singular), but the plugin is still only returning the term id. Is there something else I might try?

    Many thanks!
    Anne

    #6733
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    What do you mean by “only returning the term id”? Can you make a few screenshots how the results look like currently?
    Are there any error messages visible by any chance?

    I have no idea where the problem is, the code looks fine to me. There must be something I’m not noticing.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #6739
    ar
    ar
    Participant

    Hi Ernest!

    Thanks for getting back to me so quickly. I’m going to put up a copy of the site on a staging server to hopefully make it easier to figure out what’s wrong – what’s the best way to send you admin/ login credentials?
    Thanks Again,
    Anne

    #6740
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    Thanks! Try editing your initial post, there you can add them safely, or you can upload a .txt file with the details. Both methods are safe and visible only to me and you.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #6815
    ar
    ar
    Participant

    Hi Ernest,

    I’ve added a copy of the site I’m working on to my server, and created usernames and passwords for WP and ftp logins. (if ftp gives you trouble try port 21)

    Just to outline the file structure

    Product Post Type (post type and custom taxonomy are registered here)
    plugins/FSSproducts/index.php

    Functions file:
    I’ve added the asp filtering code to the top of the functions file to make it easier to find

    Template file:
    page-templates/FSS_collection_template.php

    Custom css
    I think I’ve moved all the custom styles to the plugin interface, but in case something is missing, most of the theme’s styles are contained in library/css/main.cc

    Lastly, I’m also have trouble setting a gutter width for the isotopic search results. For the normal grid display I’m using the standard jquery isotope plugin – would that somehow cause a conflict?

    many thanks again for all your help,
    Anne

    #6821
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    Thanks for the details! I wasn’t able to log in to the back-end, the wp-admin/ url nor the wp-login.php is taking me to a 404 page.
    What I concluded is that there is most likely an issue with your advanced title field configuration. I can’t see your back-end or configuration, but the code tells me that you have this in your advanced title field:

    {design} <span class=colorway>{colorway}</span>

    I’m not sure what this is for, but it’s certainly incorrect. If I programatically ingored this, and searched for “blue” I got the post titles like “Majestic Blue”, “Diamond Blue” and so on.. Isn’t that correct? I’m not sure what do you want to achieve.

    Can you please explain what do you want to display exactly? I might be able to tell which configuration to change and how.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #6880
    ar
    ar
    Participant

    Hi Again πŸ™‚

    the code {design} <span class=colorway>{colorway}</span>

    is just set up to add a span tag to the colorway term. I added this code at the very end, so i don’t think it’s the problem, (but what do I know?)

    Not sure why you can’t log in to either the ftp or WP site – I tested the login credentials on this end and both seem to be working.

    In any event, I’m attaching a png describing what I’m trying to accomplish.

    Again, many thanks for your help!
    Anne

    Attachments:
    You must be logged in to view attached files.
    #6909
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Oh I see the problem now πŸ™‚

    Your solution was actually almost correct. The problem was that the custom field “design” returned the term ID not the term name. Instead of that solution I’ve changed the custom code to this:

    
    add_filter( 'asp_pagepost_results', 'asp_add_term_titles', 1, 1 );
     
    function asp_add_term_titles( $pageposts ) {
      foreach ($pageposts as $k=>$v) {
        
        $colorway = "<span class=colorway>" . get_post_meta($v->id, "colorway", true) . "</span>";
        $design = get_post_meta($v->id, "design", true);
        
        if ( $design !== false ) {
          $d_term = get_term($design, "designs");
    
          if ( isset($d_term->name) )
            $pageposts[$k]->title = $d_term->name . " " . $colorway;
          
        }
      }
     
      return $pageposts;
    }
    

    this one additionally parses the design custom field, then gets the term from that field accordingly.

    As for the margin, I’ve forgotten to implement that option in the current version, I noticed too late πŸ™‚ It’s a parameter of the isotope calculation script, so it’s hard coded right now.
    However there is a workaround with CSS, but it’s not nearly as good as changing the isotope parameter. Basically adding transparent left, right border to the items appears as space, like so:

    
    .isotopic .results .item {
        border-right: 5px solid transparent !important;
        border-left: 5px solid transparent !important;
    }
    

    this basically adds 10 pixels inbetween, but 5 pixels on each side as well, so it’s not near perfect.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #6954
    ar
    ar
    Participant

    SUCCESS!!!!!! Thank you SO MUCH for all your help in getting this to work.

    One last question, does the isotope functionality come from http://isotope.metafizzy.co/? I ask because, if possible, I’d like to try and hard code the grid item and gutter widths (b/c elsewhere in the site, the grid/ gutter values are percentages (to help with responsive layouts) and I would like to keep things consistent). Is that possible? If so, can you point me to the files that I would need to edit?

    Again, thanks for helping me figure this stuff out.

    Have a great holiday season!
    Anne

    #7003
    ar
    ar
    Participant

    Hi Ernest,
    Sorry to be a pest, but I was wondering if you had a chance to look at the gutter issue with the isotope layout? (or whether or not you could point me in the right direction so I can hard-code the gutter percentage?)

    If there is no quick solution, do you think this is something you might update in future versions of the plugin? (I’m just trying to manage client expectations, etc.)

    Again, many many thanks for your help,
    Anne

    #7004
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    Sorry for the late answer. I had a similar ticket asking about the isotope margin issue, and I was able to implement it. I can’t suggest a quick fix, this turned out way more complicated than I thought as the “gutter” parameter was not working properly so I had to implement a fix as well.

    I’m attaching the pre-release version of the plugin to this reply. To install it, just deactivate and delete the current one, and install this one. Your options and data will remain in the database.

    Then make sure to clear your cache if you have any, and on the <span class=”code”>Theme Options -> Isotopic Results</span> panel you can adjust the margin between the items πŸ™‚

    Please note that this is not the final version, so it may contain bugs.

    Attachments:
    You must be logged in to view attached files.
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.