woocommerce / projects

39 stars 26 forks source link

Timber + Projects Shortcode returns current page only in projects array #122

Closed kmturley closed 7 years ago

kmturley commented 8 years ago

I would like to show my 4 most recent projects on the homepage at the url /, and show all projects at /work

I'm using the following stack: https://github.com/WordPress/WordPress https://github.com/timber/timber https://github.com/woothemes/projects

When I set the projects display page to be either home or projects pages, they are displayed correctly.

Then I use the following shortcode on the homepage:

[projects limit="12" columns="2" orderby="date" order="desc" exclude_categories=""]

This loads the entire projects page template (html, head, body tags) (which may be my Timber error), but the projects are pretty much empty, just showing the current page as the first item.

Alternatively if I bypass the shortcode and use Timber/php functions I get the same data issue:

$context = Timber::get_context();
$post = Timber::query_post();
$context['post'] = $post;
$context['posts'] = Timber::get_posts();
Timber::render( array( 'page-' . $post->post_name . '.twig', 'page.twig' ), $context );

These are the outputted results:

print_r(Timber::query_post());
TimberPost Object (
    [post_type] => page
    [slug] => home
    [post_name] => home
)

print_r(Timber::get_posts());
Array (
    [0] => TimberPost Object (
        [post_type] => page
        [slug] => home
        [post_name] => home
    )
)

Not sure if it's a bug or something i've set up wrong/compatibility with Timber. Any help you can give would be awesome!