WordPress.org

Ready to get started?Download WordPress

Forums

Random Post Link
[resolved] How to use for custom post types? (5 posts)

  1. couchseats
    Member
    Posted 2 years ago #

    I'd like the link to work on my custom post types, 'portfolio' items.

    Any idea how to change the code?

    Much thanks!

    http://wordpress.org/extend/plugins/random-post-link/

  2. dubya1337
    Member
    Posted 1 year ago #

    I figured it out:
    around line 42, look for this:

    $args = array_merge($args, array(
    			'orderby' => 'rand',
    			'showposts' => 1,
    		));

    Add this:
    'post_type' => 'your_post_type_goes_here',

    So you end up with:

    $args = array_merge($args, array(
    			'orderby' => 'rand',
    			'post_type' => 'your_post_type_goes_here',
    			'showposts' => 1,
    		));

    I'm using AppThemes Vantage, so I use 'post_type' => 'listing',

    ;-)

  3. scribu
    Member
    Plugin Author

    Posted 1 year ago #

    Or, you could use the 'random_post_args' filter defined two lines above:

    function rpl_change_ptype( $args ) {
      $args['post_type'] = 'your_post_type_goes_here';
    
      return $args;
    }
    add_filter( 'random_post_args', 'rpl_change_ptype' );

    (the code can go in your functions.php file, or in another plugin etc.)

  4. dubya1337
    Member
    Posted 1 year ago #

    Even better.

    Thanks scribu.

  5. couchseats
    Member
    Posted 1 year ago #

    Amazing! Can't wait to try this out.

    Thanks so much.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.