[Resolved] Including more than one post type

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Including more than one post type

Tagged: 

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #13208
    Michael
    Participant

    Hi Tom and team

    Is there a way to create one ‘show posts’ to include multiple post types – for example, ‘posts’ and a few cpts?

    Was thinking of using the Flint Skin Dispatch front page as a bit of a template/inspiration (on the Generate Press site library), but wanted to know if there was a way to mix in some cpts to the display.

    Many thanks for any help and ideas. Just renewed GP and an amazed at the value.

    Cheers

    Mike

    Ps apologies if I’ve missed anything obvious.

    #13241
    Tom
    Keymaster

    Hi Mike,

    It’s possible, but it’ll take some tweaking.

    Make this change in your wp-show-posts.php file: https://github.com/tomusborne/wp-show-posts/commit/286caf1164db8b6b6f38b85d3a011b519a27f4de

    Then you can do this:

    add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
        if ( 123 === $settings['list_id'] ) {
            $args['post_type'] = array( 'post', 'another-type', 'one-more' );
        }
    
        return $args;
    }, 10, 2 );

    You just need to update 123 with the ID of the list.

    #13336
    Michael
    Participant

    Many thanks Tom!

    #13350
    Tom
    Keymaster

    No problem! 🙂

    #23357
    Matt
    Participant

    Hi Tom,

    I’m trying to get posts and pages to display and I used the following code:

    add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
      if ( 93689 === $settings['list_id'] ) {
        $args['post_type'] = array( 'post', 'page' );
      }
      return $args;
    }, 10, 2 );

    I get this error in the logs:

    Error: Too few arguments to function {closure}(), 1 passed in /public_html/wp-includes/class-wp-hook.php on line 287 and exactly 2 expected in /public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(446) : eval()'d code:1
    Stack trace:
    #0 /public_html/wp-includes/class-wp-hook.php(287): {closure}()
    #1 /public_html/wp-includes/plugin.php(206): WP_Hook->apply_filters()
    #2 /public_html/wp-content/plugins/wp-show-posts/wp-show-posts.php(383): apply_filters()
    #3 /public_html/wp-content/themes/ckyf-divi/category-cours-kriya-yoga.php(8): wpsp_display()

    93689 is my list ID.

    The page blanks out where the shortcode should appear. If I remove the code snippet, the shortcode works (with posts only). Is there something else I should do?

    Thanks,
    Matt

    #23360
    Matt
    Participant

    It looks like $settings is never used: if I remove it from the function arguments and remove the number of arguments, it works but it means all shortcodes will have this condition ( posts and pages).

    #23527
    Tom
    Keymaster

    Hi there,

    You need to use the latest development version: https://wpshowposts.com/wp-show-posts-1-2-0/

    Let me know 🙂

    #23572
    Matt
    Participant

    Hi Tom,

    That works well now, thanks 🙂

    Matt

    #23659
    Tom
    Keymaster

    No problem! 🙂

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.