wordpress - Getting page ID in a template that has no loop -
i have form collects data on product , puts data wp_posts table , wp_postmeta table. can build permalink around id , if wp_redirect permalink wordpress should try display page.
the page's template called listing.php, , has no loop. purpose display these product pages placing data in wp_posts table , wp_postmeta table various divs. i'm wondering how template can id of page it's building can access wp_posts table , wp_postmeta table. i'd $meta = get_post_meta( get_the_id() )
codex says can use get_the_id()
in loop , don't have 1 of those. how should doing this?
thanks
the sound , reliable way page id of current page make use og queried object. 2 functions get_queried_object()
, get_queried_object_id()
hold info of current page (on category, tag, taxonomy , author pages hold current category, tag, term , author info respectively)
to page id, use
$page_id = get_queried_object_id(); echo $page_id;
Comments
Post a Comment