Permalinks structure in Postie functions
-
I have a function which adds a post’s permalink as a custom field called ‘share_url’, like this:
// // CREATE SHARE_URL CUSTOM FIELD - NON POSTIE // function create_share_url_customfield($post_id) { global $post; $post_url = get_permalink(); $post_url_sanitised = esc_url_raw($post_url); if ($post->post_type == 'post'){ update_post_meta($post_id, 'share_url', $post_url_sanitised); } } add_action( 'save_post', 'create_share_url_customfield' );
It works well when posting via the admin area, but posts created via Postie Plugin are not updated. For that reason, I created a Postie function:
// // CREATE SHARE_URL CUSTOM FIELD - POSTIE // add_filter('postie_post_before', 'add_share_url_custom_field'); function add_share_url_custom_field($post) { $post_url = get_permalink($post['ID']); ? ? add_post_meta($post['ID'], 'share_url', $post_url); ? ? return $post; }
This works, but the share_url takes the form of the ‘Ugly’ permalink (https://example.com/?p=N).?
How do I ensure that the first function captures all posts, including those generated by Postie? Or, alternatively, ensure that the second Postie-specific function retrieves ‘Pretty Permalinks’?
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Permalinks structure in Postie functions’ is closed to new replies.