• Hi! I have a request. Would it be possible to add an option in the shortcode that the category title should be displayed in the output?
    If you combine categories in your output display it would be nice to display the category title (e.g. like reviewer now is displayed).

Viewing 10 replies - 1 through 10 (of 10 total)
  • Hi @harm10,

    Thanks for the feedback. I haven’t ever had a request for that feature, but I’ll certainly keep it in mind.

    Thread Starter Harm10

    (@harm10)

    OK thanks for that. Is there some function available I can get the review category (or categories) belonging to the review from?
    (I see there is an output filter available for the review output)

    Hi @harm10,

    If you’re using the hook to filter the output, you can look at the output code in the plugin and copy what’s there:

    https://github.com/NateWr/good-reviews-wp/blob/master/includes/template-functions.php#L48-L222

    Once you’re looping through the posts, you can use any of the WordPress core functions to retrieve taxonomy terms. Probably the best one to use is get_terms():

    https://github.com/NateWr/good-reviews-wp/blob/master/includes/template-functions.php#L48-L222

    Thread Starter Harm10

    (@harm10)

    I already tried using get_terms() but it didn’t give me the review category name. The problem lies (I think) in the fact that the link from review id to category id is registered in wp_term_relationships (object_id -> term_taxonomy_id) and not in wp_terms. You need the term_taxonomy_id to find the name in wp_term_taxonomy.
    There are some functions for term_relationships but I couldn’t get the right call.
    Maybe you can?

    Hi @harm10,

    When using get_terms(), you need to pass the taxonomy name. Otherwise it looks for regular post categories. So to retrieve the review categories that a review is assigned to, you’d use:

    
    get_terms(array('taxonomy' => 'grfwp-category'));
    
    Thread Starter Harm10

    (@harm10)

    I tried your suggestion and it worked in one go!
    In fact it was close to some of my experiments but I always added the ID in the get function and that was probably the reason the terms were not found.

    Anyway if you are interested I have made updates to these functions to get it displayed on the summary display when using the shortcode:
    grfwp_print_reviews:
    – use get_terms in the loop whenever the new query arg is active)
    – within class gr-content to display the build string of categories (I think displaying this string at the beginning of the review display is the most logical place)
    grfwp_reviews_shortcode:
    – set the default value for the new query arg
    get_query_args:
    – accept the query arg for the display

    I can send you the changed files if you are contemplating of making this an official feature.

    Thread Starter Harm10

    (@harm10)

    I have to add something to the reply above. In fact it doesn’t work in the loop. It now shows all possible review categories and not the ones the id is attached to.
    So I do have to add some id to the get_terms function I guess. I will continue to experiment……….

    OK, that went fast. It turned out I have to add ‘object_ids’ => get_the_ID() to the get_terms call but not at the beginning of the array. That has to remain ‘taxonomy’ => ‘grfwp-category’. Then you only get the categories of the id that is processed in the loop.
    Finally! ??

    • This reply was modified 7 years, 2 months ago by Harm10.

    Hi @harm10,

    Glad you were able to get it working! I don’t think I’ll be adding that to the plugin, as this is the first request I’ve had for that feature in several years.

    Thread Starter Harm10

    (@harm10)

    I understand your reasoning. You won’t accept updates on git for it?
    If not I have to find a proper way to keep my changes whenever a new version is published.

    I’d recommend you spin off the modifications into a plugin. You can create a custom shortcode with your additional attribute and then hook into grfwp_print_reviews_output to customize the output. Keeping these changes in a separate plugin will let you update the core plugin without losing your changes.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Display category title in output?’ is closed to new replies.