• Resolved babylon324

    (@babylon324)


    Hello Greg,

    I have read the thread: https://ww.wp.xz.cn/support/topic/random-adverts_list/ regarding the random ads.

    I want to apply this random list in categories. The thing is that in that posts you said that we need to introduce this code in the shortcode:

    [adverts_list order_by=”rand”]

    The question is, how can I apply this if I’m publishing the list directly from the category section?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,

    you should be able to do that by adding the code below in the theme functions.php file (or even by creating a new blank plugin and adding the code there https://wpadverts.com/blog/how-to-use-code-snippets-in-wordpress/)

    add_filter( "adverts_tax_shortcode_args", function( $args ) {
      $args["order_by"] = "rand";
      return $args;
    } );
    Thread Starter babylon324

    (@babylon324)

    Thank you Greg.

    Is it possible to apply this filter only in one category?

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,

    yes, you can do that by checking on which page is the code being run, for example if you want to run it only on the page which slug is “random-order-category” then you can make the snippet look like this

    add_filter( "adverts_tax_shortcode_args", function( $args ) {
      if( get_queried_object()->slug == "random-order-category" ) {
        $args["order_by"] = "rand";
      }
      return $args;
    } );

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Random list in categories’ is closed to new replies.