• Resolved gasmas75

    (@gasmas75)


    Hello, I want to create a page template that has two main sections. The top will include a title, description and featured image. These data will be taken from each page data entry. The second section will include all posts referred to the page based on their tags (each tag will be similar to the page title).
    For example a tv show page with title, description and main photo and lower on the page a grid of all episodes of this show.
    Can this be done somehow with elementor/pro dynamically?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Not sure about the first past of your project but there are plug-ins that will allow you to list certain categories of posts. You can list the titles or you can even add an image and a defined excerpt from the post. Search list or display posts in the plugin area. Find one that is compatible with your version of WP.

    If you could expand on the first part it might help people offer a solution.

    Thread Starter gasmas75

    (@gasmas75)

    Hi @lestexas60 Thank you for your response.
    The 1st part is easy and I can do this by creating a page template with dynamic fields. So each time I create a new page, the dynamic fields get their respective values.
    My problem is on the second part, where I want to show a grid of posts related to the page’s title (relation can be page’s title with posts’ tag).
    One way I suppose I can do it, is by using elementor’s query id/filter. But I have some trouble creating the action hook.

    For the second part, Create categories based on the page you want to post to. The when you list the posts on that page, specify the category you want to post. Each page could have it’s own category. When a post is added, it automatically displays in the page with it’s defined category.

    Thread Starter gasmas75

    (@gasmas75)

    I understand what you’re describing. But I want to do this dynamically. Each time a user creates content for a page (actually it’s a child page from a parent page) the template displays the page’s content+the posts related.

    I’m trying to use a query filter with elementor’s query id and I must alter somehow the code provided by elementor for ‘related posts’

    `
    // Showing related posts by tag in Posts Widget
    add_action( ‘elementor_pro/posts/query/episode_q’, function( $query ) {
    // Here we set the query to fetch posts with
    // the same tags as the current post

    // Get current post tags
    $tags = wp_get_post_terms( get_queried_object_id(), ‘post_title’, [ ‘fields’ => ‘ids’ ] );

    // Get current tax_query
    $tax_query = $query->get( ‘tax_query’ );

    // Add our tax query
    $tax_query[] = [
    ‘taxonomy’ => ‘post_tag’,
    ‘terms’ => $tags,
    ];

    // Modify the query
    $query->set( ‘tax_query’, $tax_query );

    // Make sure we don’t get current post
    $not_in = $query->get( ‘post__not_in’ );
    $not_in[] = get_queried_object_id();

    // Modify the query
    $query->set( ‘post__not_in’, $not_in );
    } );
    `

    Somewhere I have to alter the code, but I can’t figure out where

    • This reply was modified 6 years, 3 months ago by gasmas75.
    • This reply was modified 6 years, 3 months ago by gasmas75.
    • This reply was modified 6 years, 3 months ago by gasmas75.

    is this what you mean?

    https://developers.elementor.com/custom-query-filter/

    // Posts Widget
    add_action( ‘elementor_pro/posts/query/tags_only’, function( $query ) {
    // Modify the posts query here
    $query->set( ‘tag’, get_the_title() );
    } );

    Thread Starter gasmas75

    (@gasmas75)

    Hi @ruven. Yes it was that simple ?? Although it seems to work on some pages, on other doesn’t return posts (even though they exist) and on others returns less than the actual posts.
    I’ll examine more carefully, maybe some tags/slugs aren’t exactly as the page’s name.
    But you helped me to get in the right track!
    Many thanks!

    Thread Starter gasmas75

    (@gasmas75)

    To elevate @ruven ‘s answer because some posts didn’t display at all for some reason, I found that using the function below solves the issue and displays the posts everytime:


    add_action( ‘elementor_pro/posts/query/tags_only’, function( $query ) {
    $query->set( ‘tag’, get_post_field( ‘post_name’, get_post() ) );
    } );

    • This reply was modified 6 years, 3 months ago by gasmas75.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Page template with mixed dynamic content’ is closed to new replies.