php - How to process shortcodes with post_id outside `The Loop` -
i'm reading emails using postie.
i'm using following filter process keywords inside email , convert them wp_postmeta items.
//look ':keyword attribute:' tags , convert them '[keyword attribute]' function filter_content($post) { $content = $post['post_content']; $length = strlen($content); $pos = array( 'name' => strpos($content, ':name '), 'cost' => strpos($content, ':cost '), 'price' => strpos($content, ':price ') ); foreach ($pos $key => $value) { if (false !== $value) { $content[$value] = '['; $value = strpos($content, ':', $value+1); if ( (false !== $value) && (ctype_alnum($content[$value-1])) ) {$content[$value] = ']'; } } } //if there no name attribute steal subject line. if (strpos($content, '[name ') === false) { $content = ' [name ' . $post['post_name'] . '] ' . $content; } $post['post_content'] = $content; return $post; }
function resolve_shorttags($post) { $content = $post['post_content']; $content = do_shortcode($content); $post['post_content'] = $content; wp_update_post($post); storedefaults($post['id']); return $post; }
because i'm running do_shortcode
outside of the loop
. get_the_id()
not work. need post_id
in order processing work correctly.
how pass post_id
of posts process in resolve_shorttags()
shorttag hooks?
remarks
know resolved if leave shorttags in , wait display time , loop process shorttags, want process data beforehand.
if there way process specific shortcodes or shortcode keys , attributes i'd happy also. can call handlers manually. don't want write own shortcode parser.
Comments
Post a Comment