Support » Plugin: Strong Testimonials » Sort by Custom Field

  • Resolved Kelsey Ariel Piche

    (@keslerpiche)



    Hello, I am looking for a testimonial plugin that will allow me to sort by date – NOT the date that the testimonial is uploaded, but the date that goes along with the testimonial.

    Back story -> The company receives testimonials by email and then uploads them in batches. Currently they have a WordPress page “Testimonials” that they upload new content to in the date order they received the comments. They do this because the testimonial plugin they have doesn’t work they way they like. BUT they use the widget, which doesn’t get updated because they don’t use the plugin. So testimonial page has 2 more years of comments then the last comment on the plugin (2015 — I have since added new comments so that it isn’t so behind).

    I would like a plugin where I input the date the testimonial was given, the author name and the comments. And then be able to insert shortcode into a page specifying sort by date in field.

    Can I do this with your plugin?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Chris Dillon

    (@cdillon27)

    Hi Kelsey,

    Thanks for providing the context. Yes, you can do this.

    The plugin includes sorting by post date in ascending (oldest first) or descending (newest first) order. This date can be edited in the post editor.

    post date

    view order

    There is also a filter on the query for more advanced sorting.

    There is also a filter on the query for more advanced sorting.

    Tell us more?

    Plugin Author Chris Dillon

    (@cdillon27)

    For example, to order by a custom field (‘company_name’ in this case):

    function my_testimonial_query_args_1( $args, $atts ) {
        $args['orderby'] =  'meta_value';
        $args['meta_key'] = 'company_name';
    
        return $args;
    }
    add_filter( 'wpmtst_query_args', 'my_testimonial_query_args_1', 10, 2 );

    To include only ones with a company name:

    function my_testimonial_query_args_2( $args, $atts ) {
      $args['meta_query'] = array(
        array(
          'key' => 'company_name',
          'value' => '',
          'compare' => '!=',
        )
      );
    
      return $args;
    }
    add_filter( 'wpmtst_query_args', 'my_testimonial_query_args_2', 10, 2 );
    

    https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

    Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sort by Custom Field’ is closed to new replies.