WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
[resolved] Display metabox only for specific post ID or specific teplate (32 posts)

  1. obvio
    Member
    Posted 2 years ago #

    Hi,

    Thanks for this great plugin!

    I wanted to ask if its possible to show the metabox only on a specific Page/Post ID or specific page-template (or even custom field), I sometimes need to create those connections only for specific pages in an entire site (I'm looking for a solution like http://www.farinspace.com/wpalchemy-metabox/#exclude_include_options).

    Thanks again!

    http://wordpress.org/extend/plugins/posts-to-posts/

  2. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    The main difficulty is this: the P2P metaboxes also show up when creating a new post. You can't check these kinds of conditions until after the post is created.

  3. obvio
    Member
    Posted 2 years ago #

    Hi, thanks for the fast response.

    This is 'not that of a concern' (ie. I can live with that) because usually pages will be preset for the user, or in case not, a user-manual can always include 'use X page template, save your page to enable all boxes.. and continue editing', at least that's the case with WPAlchemy (linked above).

    Thanks again!

  4. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    I won't be adding any parameters for this, but I did introduce a new filter, present in the development version (1.3-alpha2).

    Example usage:

    function restrict_p2p_box_display( $show, $post, $ctype ) {
    	if ( 'YOUR_CONNECTION_TYPE' == $ctype->name ) {
    		return ( 'YOUR-TEMPLATE.php' == $post->page_template );
    	}
    
    	return $show;
    }
    
    add_filter( 'p2p_admin_box_show', 'restrict_p2p_box_display', 10, 3 );
  5. obvio
    Member
    Posted 2 years ago #

    Amazing! works great!
    thanks!

  6. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    In the development version (1.3.1-alpha), I changed the parameter order, to be consistent with the other filters. When you update, you'll have to replace this:

    function restrict_p2p_box_display( $show, $post, $ctype ) {

    with:

    function restrict_p2p_box_display( $show, $ctype, $post ) {

    Sorry for the inconvenience.

  7. Twansparant
    Member
    Posted 2 years ago #

    Hi scribu,

    What if you only want to display the Admin Box for a certain connection type on one specific page? How would I do that? Let's say I want to connect a post from a certain post-type only from page with ID = 14.

    My code does work, the box only shows up on the specific page, but when I try to connect a post, it doesn't find any...

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    Am I doing something wrong, or is it not possible yet with this function?
    Many thanks as always!

  8. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    Your code got moderated.

  9. Twansparant
    Member
    Posted 2 years ago #

    Sorry about that...
    Here's my code in pastebin
    Thanks!

  10. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    This should be fixed in the development version (1.4-alpha).

    More info: https://github.com/scribu/wp-posts-to-posts/issues/175

  11. Twansparant
    Member
    Posted 2 years ago #

    Yes, fixed! :) Brilliant!
    One thing I noticed though in this alpha version, is that in all the Admin boxes underneath the 'search' tab, all the posts are shown with navigation arrows. I believe those were only visible when you searched for something in the previous versions?
    Thanks for your swift action!

  12. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    Screenshot please.

  13. Twansparant
    Member
    Posted 2 years ago #

    There you go:
    http://imageshack.us/f/801/schermafbeelding2012060.png/

    As you can see, below the search type fields, all the possible connections are allready visible. The Admin Boxes use a lot more space like this. I think this wasn't like that in previous versions?

    Thanks!

  14. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    Oh, yeah, that's an intentional change. If you want to make a case against it, please comment here:

    https://github.com/scribu/wp-posts-to-posts/issues/170

  15. Twansparant
    Member
    Posted 2 years ago #

    Ah okay, was wundering about that... No need to make a case against it :)
    Thanks!

  16. Twansparant
    Member
    Posted 2 years ago #

    Hi scribu,
    The above code doesn't work anymore after updating from the development 1.4-alpha to the 1.4 version... The connection box on that page only is still there and the connections too, but it doesn't show any connected posts anymore on the frontend.
    Any ideas? Thanks!

  17. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    "The above code" is pretty vague, since you say that the 'p2p_admin_box_show' filter still works.

  18. Twansparant
    Member
    Posted 2 years ago #

    Hi scribu,
    Sorry you are absolutely right, the code I pasted in pastebin is regarding the backend connection which still works. I don't have the frontend code on me right now so I will have to get back to you on that. I downgraded to the 1.4-alpha and it's working again somehow...
    Will get back to you when I can!
    Thanks, Toine

  19. Twansparant
    Member
    Posted 2 years ago #

    Hi Scribu,

    Sorry it took so long, I was away on holiday.
    First of all when I update the posts-to-posts 1.4-alpha to the posts-to-posts 1.4.1 version, I get the following error in the WP admin:

    Warning: get_object_vars() expects parameter 1 to be object, null given in /path-to-wordpress-installation/wp-content/plugins/posts-to-posts/core/side.php on line 83

    Besides that, some connections just simply dissapear. For example, the following connection I defined in my functions.php doesn't show up anymore after the update, while the connections in the admin page ares till there: http://pastebin.com/ajEg1Hdk

    The 1.4 version simply just not work for me I'm afraid.
    Any ideas on what may be causing these failures?

    Thanks again for your time!

  20. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    What does get_queried_object() return on the "homepage template" ?

    Warning: get_object_vars() expects parameter 1 to be object, null given

    That's usually an indication that the post type doesn't exist.

  21. Twansparant
    Member
    Posted 2 years ago #

    What do you mean exactly with 'What does get_queried_object() return on the "homepage template"'? How can I test/print this?

    The post type does exist because right now all my connections work perfectly without any errors with the 1.4-alpha version, that's the weird thing about it... The moment I update, I get the error and my connection on the homepage is gone.

  22. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    How can I test/print this?

    http://php.net/var_dump

  23. Twansparant
    Member
    Posted 2 years ago #

    Thanks, here's my output of the var_dump in pastebin:
    var_dump(get_queried_object());

    The page ID seems to be right: ["ID"]=> int(14)
    Only thing that seems weird is the part after ["guid"]=> string(60)
    that's an very old and outdated url, but I don't think that has got anything to do with these problems...

  24. Twansparant
    Member
    Posted 2 years ago #

    I really don't get it...

    I cleaned up my p2p_register_connection_type codes to the latest syntax and tried to update again to 1.4.1 and at least the error has dissapeared.

    However some of my connections still dissapear but only on the frontend! In the WP backend under Tools > Connection Types they're all there!

    I'm using the following code in my sidebar.php and it just won't work:
    http://pastebin.com/69DivrNX

    When I echo the amount of connections: echo count($connected);
    it just keeps returning 1 while at the backend there are 4 connections present!

    Any help would be appreciated, thanks!

  25. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    count($connected) will always return 1. What you need is count($connected->posts).

    Are you sure those 4 posts have 'post_status' => 'publish'?

  26. Twansparant
    Member
    Posted 2 years ago #

    Yup, I'm sure! count($connected->posts) returns 0 by the way

    I discovered something weird though, I copied both the 1.4-alpha as well as the 1.4.1 plugin folders into the wp-content/plugins folder and renamed the 1.4.1 version to: posts-to-posts-1.4.1. So the 1.4-alpha plugin is till named posts-to-posts. Then I activated the 1.4.1 version and everything works all of a sudden! When I delete the 1.4-alpha folder I obviously get an error but there's some function in the 1.4-alpha version that's different somehow...

  27. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    Please send me this '1.4-alpha' version you have in a zip: mail @ scribu.net

  28. Twansparant
    Member
    Posted 2 years ago #

    Done!

  29. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    Hm... I don't see it. Try scribu @ gmail.com instead.

  30. Twansparant
    Member
    Posted 2 years ago #

    Got it?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic