0

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

2
  • 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
    Commented Mar 5, 2013 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
    Commented Mar 5, 2013 at 1:56

4 Answers 4

0

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.

3
  • 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
    Commented Mar 5, 2013 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.
    – Brooke.
    Commented Mar 5, 2013 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
    Commented Mar 5, 2013 at 17:16
0

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>
1
  • 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
    Commented Mar 21, 2013 at 11:49
0

Try this

PHP

function quickPressBox() {
    echo '<div id="quick_press_box">content....</div>';
}
add_action('admin_footer', 'quickPressBox');

JQUERY

<script type="text/javascript">
   jQuery(function($)  {

      $("#quick_press_box").appendTo(".wrap");

   });
</script>
1
  • Answers should be more than code snippets. Please file an edit and explain why this would work.
    – Gabriel
    Commented Apr 29, 2015 at 18:53
-1

Please consider this code:

global $pagenow, $page;
if ( 'edit.php' = $pagenow && '123' == $post->ID ) {
    add_meta_box( $args );
}
2
  • Can you explain why this works? Commented Mar 21, 2013 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
    Commented Mar 21, 2013 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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