“Exclude current post” not working in template part
-
Hello,
I’m working on an FSE website and have created a CPT called “Product.” In the single template of this CPT, I’ve set up an AQL query to display other products while excluding the current one. If the AQL is directly set in the template part it work. BUT if i use this AQL in a template part inside the single template this doesn’t work. I use a lot template-parts to split my template and it is frustrated that AQL doesn’t work in this case.
-
Hello and thanks for using AQL! I am sorry you’re running into this issue. I have tried to reproduce this locally and it seems to work for me when AQL is both nested in a template part and not.
Are your template parts stored in files or in the database?
Can you share how the code for the template part that doesn’t work?
Here is my single template
<!-- wp:template-part {"slug":"header","theme":"aqualarm","tagName":"div","bsawebNoWrapper":true} /-->
<!-- wp:group {"tagName":"main","metadata":{"name":"Main"},"style":{"spacing":{"blockGap":"0px","margin":{"top":"0"}}},"bsawebA11y":{"ariaRole":"main"}} -->
<main class="wp-block-group" style="margin-top:0"><!-- wp:group {"tagName":"article","metadata":{"name":"Article"},"style":{"spacing":{"blockGap":"0px"}},"layout":{"type":"default"}} -->
<article class="wp-block-group"><!-- wp:template-part {"slug":"single-aqualarm-product-header","theme":"aqualarm","tagName":"section","bsawebNoWrapper":true} /-->
<!-- wp:template-part {"slug":"aqualarm-products-single-before-content","theme":"aqualarm","area":"aqualarm-single","bsawebNoWrapper":true} /-->
<!-- wp:post-content {"style":{"spacing":{"blockGap":"0"}},"layout":{"type":"constrained"}} /-->
<!-- wp:template-part {"slug":"aqualarm-products-single-after-content","theme":"aqualarm","area":"aqualarm-single","bsawebNoWrapper":true} /--></article>
<!-- /wp:group --></main>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","theme":"aqualarm","tagName":"div","bsawebNoWrapper":true} /-->The AQL is call within
aqualarm-products-single-after-contenttemplate-part.And here is the what is inside the template-part :
<!-- wp:group {"tagName":"section","metadata":{"name":"Section"},"align":"full","style":{"spacing":{"padding":{"top":"var:preset|spacing|9-xl","bottom":"var:preset|spacing|9-xl"}}},"backgroundColor":"base","layout":{"type":"default"}} -->
<section class="wp-block-group alignfull has-base-background-color has-background" style="padding-top:var(--wp--preset--spacing--9-xl);padding-bottom:var(--wp--preset--spacing--9-xl)"><!-- wp:group {"style":{"spacing":{"blockGap":"var:preset|spacing|7-xl"}},"layout":{"type":"constrained"}} -->
<div class="wp-block-group"><!-- wp:heading {"textAlign":"center"} -->
<h2 class="wp-block-heading has-text-align-center">Les produits qui pourraient vous plaire</h2>
<!-- /wp:heading -->
<!-- wp:query {"queryId":1,"query":{"perPage":3,"pages":0,"offset":0,"postType":"aqualarm-products","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false,"parents":[],"format":[],"disable_pagination":true,"include_posts":[],"meta_query":[],"exclude_current":"aqualarm//aqualarm-products-single-after-content"},"namespace":"advanced-query-loop","metadata":{"categories":["compositions-aqualarm","posts"],"patternName":"core/block/333","name":"Grille Produits"}} -->
<div class="wp-block-query"><!-- wp:post-template {"style":{"spacing":{"blockGap":"var:preset|spacing|4-xl"}},"layout":{"type":"grid","columnCount":3}} -->
<!-- wp:template-part {"slug":"aqualarm-products-card","theme":"aqualarm","area":"aqualarm-card"} /-->
<!-- /wp:post-template -->
<!-- wp:query-no-results -->
<!-- wp:paragraph {"placeholder":"Ajouter un texte ou des blocs qui s’afficheront lorsqu’une requête ne renverra aucun résultat."} -->
<p></p>
<!-- /wp:paragraph -->
<!-- /wp:query-no-results --></div>
<!-- /wp:query --></div>
<!-- /wp:group --></section>
<!-- /wp:group -->If I put this section directly in template the attribute
"exclude_current"change :<!-- wp:group {"tagName":"section","metadata":{"name":"Section"},"align":"full","style":{"spacing":{"padding":{"top":"var:preset|spacing|9-xl","bottom":"var:preset|spacing|9-xl"}}},"backgroundColor":"base","layout":{"type":"default"}} -->
<section class="wp-block-group alignfull has-base-background-color has-background" style="padding-top:var(--wp--preset--spacing--9-xl);padding-bottom:var(--wp--preset--spacing--9-xl)"><!-- wp:group {"style":{"spacing":{"blockGap":"var:preset|spacing|7-xl"}},"layout":{"type":"constrained"}} -->
<div class="wp-block-group"><!-- wp:heading {"textAlign":"center"} -->
<h2 class="wp-block-heading has-text-align-center">Les produits qui pourraient vous plaire</h2>
<!-- /wp:heading -->
<!-- wp:query {"queryId":1,"query":{"perPage":3,"pages":0,"offset":0,"postType":"aqualarm-products","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false,"parents":[],"format":[],"disable_pagination":true,"include_posts":[],"meta_query":[],"exclude_current":"aqualarm//single-aqualarm-products"},"namespace":"advanced-query-loop","metadata":{"categories":["compositions-aqualarm","posts"],"patternName":"core/block/333","name":"Grille Produits"}} -->
<div class="wp-block-query"><!-- wp:post-template {"style":{"spacing":{"blockGap":"var:preset|spacing|4-xl"}},"layout":{"type":"grid","columnCount":3}} -->
<!-- wp:template-part {"slug":"aqualarm-products-card","theme":"aqualarm","tagName":"article","area":"aqualarm-card","bsawebNoWrapper":true} /-->
<!-- /wp:post-template -->
<!-- wp:query-no-results -->
<!-- wp:paragraph {"placeholder":"Ajouter un texte ou des blocs qui s’afficheront lorsqu’une requête ne renverra aucun résultat."} -->
<p></p>
<!-- /wp:paragraph -->
<!-- /wp:query-no-results --></div>
<!-- /wp:query --></div>
<!-- /wp:group --></section>
<!-- /wp:group -->
The topic ‘“Exclude current post” not working in template part’ is closed to new replies.