Comments 3Norman started the conversationApril 27, 2020 at 4:02pmI'm creating a widget with items (enable items). Each item has 1 links to a post. I'd like to print the post-ID of that post. How can you achieve that in twig?Can anybody give me some direction how to achieve this? 1,194Amit repliedApril 27, 2020 at 4:04pmare you using post list ? 3Norman repliedApril 27, 2020 at 4:05pmNo I'm using a link. Can't use a post list because I need some extra attributes on it. (like the hotspot x and y coordinates). 3Norman repliedApril 28, 2020 at 6:56am(https://unlimited-elements.helpscoutdocs.com/article/81-php-integration-get-data-from-php) I just figured out from the documentation that you can call any PHP function with {{ do_action('some_action','param1','param2','param3') }} So now I'm doing this.. {{ do_action( 'url_to_postid', 'item.link' ) }} This wordpress function should return the postid from the slug. But no luck :( Any idea what's going wrong)? 3Norman repliedApril 28, 2020 at 7:32amOk.. what I learned and what works is this: I added a custom filter in my function.php add_filter( 'getID', 'get_my_id' ); function get_my_id( $myslug ) { $postid = url_to_postid( $myslug ); return $postid; } In the html field (twig template) I'm doing this: {% set itemID = apply_filters('getID', item.link|raw ) %} {{ itemID }} This way I get the ID of the linked post. :) Max replied privately Sign in to reply ...
I'm creating a widget with items (enable items). Each item has 1 links to a post. I'd like to print the post-ID of that post. How can you achieve that in twig?
Can anybody give me some direction how to achieve this?
are you using post list ?
No I'm using a link. Can't use a post list because I need some extra attributes on it. (like the hotspot x and y coordinates).
(https://unlimited-elements.helpscoutdocs.com/article/81-php-integration-get-data-from-php)
I just figured out from the documentation that you can call any PHP function with
So now I'm doing this..
This wordpress function should return the postid from the slug. But no luck :( Any idea what's going wrong)?
Ok.. what I learned and what works is this:
I added a custom filter in my function.php
In the html field (twig template) I'm doing this:
This way I get the ID of the linked post. :)