Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter to query loop post template #46590

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

huubl
Copy link
Contributor

@huubl huubl commented Dec 15, 2022

What?

Adding a filter to query loop post template block content.

Why?

Having a way to make exceptional changes. This gives developers more options to do things that are not (yet) possible with the Block Editor.

How?

By adding this or a similar filter (and maybe even others, e.g. to add classes/attributes dynamically or to change the ul > li to something)

Testing Instructions

Add to functions.php and change the queryId (or remove the IF statement)

add_filter('post_template_block_content', function($content, $query, $queryId) {
    if($queryId === 123){
        return '<p>Post #'. $query->current_post . '</p>'. $content;
    }

    return $content;
}, 10, 3);

Testing Instructions for Keyboard

Screenshots or screencast

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Dec 15, 2022
@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @huubl! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@huubl huubl changed the title Add filter to query loop post template content Dec 16, 2022
@skorasaurus skorasaurus added the [Block] Query Loop Affects the Query Loop Block label Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Query Loop Affects the Query Loop Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository
2 participants