SOLVED: Heading in custom loop is always referring to the main page

Browser: Safari, Arc, Chrome
OS: macOS
URL: Get Your Game On with the Coffee and Board Games T-Shirt | Zandalus Nerd Shop

I created a custom loop option for related products:

function setup_bricks_query($control_options): array
{
    $control_options['queryTypes'][RELATED_PRODUCTS_ID] = esc_html__( 'Related Products' );
    return $control_options;
}

function run_custom_queries($results, $query_obj ) {

    if ( $query_obj->object_type === RELATED_PRODUCTS_ID ) {
        $settings = $query_obj->settings;
        $results = run_related_products_query($settings);
    }

    return $results;
}

The query is working fine, and itā€™s returning the results I want. Even when I print a log of the results, all datas are correct.

The problem is that when I do the query loop of the custom type, all headings refer to the page Iā€™m on instead of the queried content. The problem appears only when Iā€™m using a custom loop. If I use the standard ā€œPost, User, etc.ā€ loop everything works fine.

In this image:

I did put a sign on every heading component Iā€™m using in this loop. As you can see, all headings refer to the page Iā€™m on, while the basic text correctly refers to looped content and gets the right result.

The structure of this part is really simple:

Iā€™ve tried changing run_related_products_query, but I donā€™t think thatā€™s the problem, because the log always returns the right results, and the non-heading components are reading the correct result.

Iā€™m here in case you need some more information.

Hi @Zandalus ,

As this is related to your custom code (Custom query loop), I moved your thread to ā€œDevelopersā€ section.

Please check if you have set the correct object type for your custom loop

All these hooks needed for your custom loop.

Regards,
Jenn

1 Like

Hi @itchycode,

thanks, I did find the error and fixed it!