Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've been googling this for a while, and came across this link here: Can I limit this meta box to a particular page?

What I am trying to achieve is adding a custom Meta Boxe I created onto a CPT Posts Screen (edit.php?post_type=custom).

What I tried to use is this:

add_action("admin_init", "admin_init");
function admin_init() {
   global $pagenow, $page;
      if ( 'edit.php' == $pagenow ) {
         add_meta_box( $id, $title, $callback, $post_type, $context, $priority, $callback_args );
      }
}

When adding and saving this into my functions.php, the page turns blank.

Is it even possible to add a meta box to edit.php pages?


EDIT OP wants to add the "QuickPress" functionality in this meta box. Screenshots from the comments to an answer.

enter image description here

share|improve this question
    
the page is blank because you have an error in 'edit.php' = $pagenow, should be 'edit.php' == $pagenow, enable debugging so you can see PHP errors. HOWEVER, you can't add a meta box to a post list screen, they are for individual posts. what are you trying to do with this meta box exactly? you specify a certain post ID on a page that lists multiple posts. –  Milo Mar 5 '13 at 1:49
    
Hi Milo, Thanks for the comment. The '==' fixed the blank page, and I also removed the post ID. What I am trying to achieve is a "Quick Post", just like how there is a "Quick Edit". However, I assumed it would be easy to do since there is no category, or long post to make. Basically, it's adding a post title, and an excerpt. So I wanted to place a Meta Box underneath the wp-table-list. Do you think this will still be possible to do? Assuming from your answer, a Meta Box will not be the way to go. –  Roc Mar 5 '13 at 1:56

3 Answers 3

up vote 0 down vote accepted

From your comment, it sounds like you don't want a metabox. A metabox is used to add metadata to a particular post, not create a new post from scratch. What it sounds like you want to do is create a widget to do what you want and then invoke it through an action or filter at the top/bottom of the page. You can use the existing Quick Post dashboard widget as your base.

share|improve this answer
    
Thanks Gary, Thanks for the direction. Is there a function I can use to display the QuickPress widget onto a CPT Posts List page? I assume I will have to duplicate the widget (create a new one) and start from there. What I will be lost on is how to call the widget to display to the specific admin page. Thanks for the help again. –  Roc Mar 5 '13 at 2:51
1  
Wait What? So you want the quick press link to show up where? Under the main menu of your CPT? Cuz that's TOTALLY another question. –  BandonRandon Mar 5 '13 at 5:30
    
I want QP to show under the edit.php page. I was able to accomplish this, but it will only publish into the default "Post". Attached a screen shot of how it looks. It does show & post correctly. However, what I am working on now is how to either a. reload the table, or b. reload the entire page. Currently When submitting the QP post, the default "Post Publish" message appears, with the post not showing in the table (which is what I knew will happen). I worked a way to reload the page on onclick of the Publish button, but it doesn't save the post. i.imgur.com/QKHkEqs.jpg –  Roc Mar 5 '13 at 17:16

Update - So I am able to reload the page after the post is saved, but I know it is a bit "hacky". Basically, when you submit a QP post, the form renders to display a "update" message.

What I did was added a Jquery function to reload the page whenever "#dashboard_quick_press .updated" is shown.

Once finished I can also upload the new code I wrote if anyone would like. Feel free to chime in if there is a better solution (which I know there definitely is). Hopefully we both can make it better. If it's okay, I rather finish the coding before I mark as answered. Thanks!

<script type="text/javascript">
   jQuery(function($)  {
      $("#dashboard_quick_press .updated").each( function() {
         location.reload();
      });
   });
</script>

__

New JS to refresh the wp-list-table instead of reloading entire page:

<script type="text/javascript">
   jQuery(function($)  {
      $("#dashboard_quick_press .updated").each( function() {
         $("#posts-filter").load('/supreme/wp-admin/edit.php #posts-filter'); 
         return false;
      });
   });
</script>
share|improve this answer
1  
Your comment on Gary's answer should be added as clarification to the Question itself. I only understood the Q fully after seeing that snapshot. Do you have this working? How did you make a meta box appear in that screen? –  brasofilo Mar 21 '13 at 11:49

Please consider this code:

global $pagenow, $page;
if ( 'edit.php' = $pagenow && '123' == $post->ID ) {
    add_meta_box( $args );
}
share|improve this answer
    
Can you explain why this works? –  Brian Fegter Mar 21 '13 at 12:05
    
'edit.php' = $pagenow won't work, as it's trying to assign $pagenow to the string 'edit.php'... Also: You aren't using $page anywhere. Why call it from the global namespace? And then you're calling the ID from a (possibly global) $post object. This really won't work. More bugs than lines of code :P –  kaiser Mar 21 '13 at 12:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.