• I am creating a portfolio for multiple artists. To do so I have created a ‘template-page’ and ‘template-portfolio-item’ php file for each artist and each of their images respectively. For example: John Smith’s portfolio page would be called: ‘template-smith-page’ and a page for one piece of his artwork would be called: ‘template-smith-portfolio-item’. This all works perfectly well.

    However, on the home page I am unable to show all ‘template-portfolio-item’s belonging to all artists. For example:

    
    // Get posts assigned to the template-portfolio-item.php template
    $args = array(
        'post_type' => 'page',
        'meta_key' => '_wp_page_template',
    	'meta_value' => 'template-smith-portfolio-item.php',		
    	'post_status' => 'publish',
        'posts_per_page' => $portfolio_items,
    	'orderby' => 'meta_value',
    	'order'   => 'ASC',
        'paged' => $paged
    );
    

    This piece of code will return all of John Smith’s artwork on the home page. But if I wanted to also have another artist’s portfolio items appear after John Smith’s e.g. template-smith-portfolio-item && template-campbell-portfolio-item; then I begin to have problems, and either no portfolio items appear or the most recent ones replace the old ones.

    How would I go about changing the code so I can display all images from multiple template-portfolio-item PHP files?

    I have so far tried:

    Multiple meta_value variables
    meta_query ‘s
    multiple WP_Query ‘s

    If you could help me I’d appreciate it a lot otherwise I will have to manually enter the images on to the homepage which will prove very time consuming.

    Thanks and thanks for the great theme.

    • This topic was modified 7 years, 8 months ago by mejg93.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Theme Author Themeora

    (@themeora)

    Hi

    I think you’ll need to do the meta query as a set of arrays. Something like the example below (not tested):

    $args = array(
    ‘post_type’ => ‘page’,
    ‘meta_query’ => array(
    array(
    ‘meta_key’ => ‘_wp_page_template’,
    ‘meta_value’ => ‘template-smith-portfolio-item.php’,
    ),
    array(
    ‘meta_key’ => ‘_wp_page_template’,
    ‘meta_value’ => ‘template-jones-portfolio-item.php’,
    ),
    ),
    ‘post_status’ => ‘publish’,
    ‘posts_per_page’ => $portfolio_items,
    ‘orderby’ => ‘meta_value’,
    ‘order’ => ‘ASC’,
    ‘paged’ => $paged
    );

    Thanks

    Thread Starter mejg93

    (@mejg93)

    Got it working somewhat with that, will have another fiddle with it. Thanks!

    • This reply was modified 7 years, 8 months ago by mejg93.
    Thread Starter mejg93

    (@mejg93)

    $args = array(
        'post_type' => 'page',
        'meta_query' => array(
    		array(
    			'meta_key' => 'template',
    			'meta_value' => 'template-smith-portfolio-item.php',
    		),
    		array(
    			'meta_key' => '_wp_page_template',
    			'meta_value' => 'template-johnson-portfolio-item.php',
    		),
    	),	
    	'post_status' => 'publish',
        'posts_per_page' => $portfolio_items,
    	'orderby' => 'meta_value',
    	'order'   => 'ASC',
        'paged' => $paged
    );

    This works somewhat, however, it seems to just post all portfolio items, rather than just those belonging to Smith and Johnson template portfolio items.

    The below code produces exactly the same results. It should show only Smith’s template-portfolio-items but instead shows all template-portfolio-items.

    $args = array(
        'post_type' => 'page',
        'meta_query' => array(
    		array(
    			'meta_key' => 'template',
    			'meta_value' => 'template-smith-portfolio-item.php',
    		)
    	),
    	'post_status' => 'publish',
        'posts_per_page' => $portfolio_items,
    	'orderby' => 'meta_value',
    	'order'   => 'ASC',
        'paged' => $paged
    );

    Any solution for this? I know I have complicated things beyond what the theme was intended for but it would be good to be able to get to the bottom of this for future development.

    Thanks.

    Thread Starter mejg93

    (@mejg93)

    I’ve worked out that what is doing this is ‘post_type’ => page that is posting all page featured images to the home page when the ‘meta_query’ is active. It is only overridden when just one ‘meta_key’ and ‘meta_value’ is set. Strange.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show portfolio items from multiple templates on the home page’ is closed to new replies.