I inherited a Wordpress wordpress plugin which makes custom fields available when editing pages and/or posts. It adds slightly different content for pages of computer does for posts. The wordpress plugin determines page or publish using the following:

if(preg_match('|post.php|i', $_SERVER['SCRIPT_NAME']) || preg_match('|post-new.php|i', $_SERVER['SCRIPT_NAME'])) {
        add_meta_box('qaws_' . $cg ,$group, 'qaws_admin_meta', 'post', 'advanced', 'core');
    } elseif(preg_match('|page.php|i', $_SERVER['SCRIPT_NAME']) || preg_match('|page-new.php|i', $_SERVER['SCRIPT_NAME'])) {
        add_meta_box('qaws_' . $cg ,$group, 'qaws_admin_meta', 'page', 'advanced', 'core');

This labored fine in older versions of Wordpress simply because they used publish.php within the URL when editing posts and page.php when editing pages. Now, however, Wordpress doesn't do that. Both posts and pages are edited having a URL that appears like: post.php?post=4&action=edit therefore the only possible identifier within the URL may be the publish number.

So, wouldso would I identify whether I'm editing a webpage or perhaps a publish? It is possible to Wordpress function that may readily let me know this? Is your best option to seize the publish number and in some way check it to determine what it's?

How does one approach this?

EDIT: Here's what Used to do... instead of doing the preg_match I retrieved the worldwide $id, used get_all_page_ids() to obtain a listing of all the pages and matched up the $id towards the ids within the get_all array. If there's a match, perform the page add_meta_box, otherwise perform the publish one.

I additionally moved the looking at of the loop it had been by which saved a lot promptly to render the page. Now I set a flag right in the beginning and informed the renders these meta_boxes just determine in the event that flag isset.

It might be easier to use get_publish_type($id)


May be the function is_page() open to your wordpress plugin?

See here: http://codex.wordpress.org/Conditional_Tags