By using Elementorforum.com’s services you agree to our Cookies Use and Data Transfer outside the EU.
We and our partners operate globally and use cookies, including for analytics, personalisation, ads and Newsletters.

  • Join the Best Unofficial Elementor Support forum

    Provide or get advice on everything Elementor and Wordpress, ask questions, gain confirmation or just become apart of a friendly, like minded community who love Wordpress and Elementor


    Join us!
elementor official

Custom querying the posts widget

J

joelinit

New Member
Hey all! Looking for a bit of help with custom querying my post widget. I can use the below hook to get the page title and use it as the category name for my posts...

add_action( 'elementor/query/test_filter', function( $query ) {
$category_name = get_the_title();
$query->set( 'category_name', $category_name );
} );

Elsewhere however, I'd like to use the page title as the tag for my query, but what I thought would be a straightforward adaptation of the above isn't working!

add_action( 'elementor/query/test_filter', function( $query ) {
$tag_name = get_the_title();
$query->set( 'tag', $tag_name );
} );

Anyone got any ideas?! Thanks in advance!
 
elementor official
Koni Kodes

Koni Kodes

Member
What does it see the tag_name as instead?
Perhaps you should set it as page_name and try to get_the_page-name?
 
elementor official
J

joelinit

New Member
Thanks for your reply and suggestion! My query above returns no results. The get_the_title request is working - I can use it to query by category as per my first hook above.

Likewise, if I set a tag manually (ie $query->set( 'tag', 'tag1' ); the post widget will populate with the relevant posts. However, using get_the_title and querying it as my tag isn't.

Any more thoughts?! Thanks in advance for any replies!
 
elementor official
Koni Kodes

Koni Kodes

Member
There are widgets that pull the tags - like woocommerce product queries. There must be a way to look inside and see how they make it work. You've given me a new research project.

I'm sorry I can't be more help right now.
 
elementor official
J

joelinit

New Member
Resolved! -ish!!

get_the_title(); returns the title, without hyphens whereas the queried tag needs to be hyphenated it'd seem...
 
elementor official

Latest posts

Other Elementor Resources

elementor official
elementor official
Top