Relationships on post_status other than Published

Support MB Relationships Relationships on post_status other than Published

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #32780
    Michele SchembriMichele Schembri
    Participant

    Hi,

    I'm currently using MB Relationships, and everything is working fine. I noticed however that in the relationship admin column, only posts that are published show. I looked at the documentation and couldn't find anywhere on how I can show even posts that are still in draft in these lists.

    The reason is that even though a post might not be published on the front end, one might still want to show it in a list or something in the front end, without linking to the page. Is there any way I can define the post_status for which posts to show in the relationship dropdown?

    Thanks.

    #32791
    Long NguyenLong Nguyen
    Moderator

    Hi Michele,

    You can use the parameter query_args to pass the post_status to the query to get posts by status. For example

    function your_prefix_function_name() {
        MB_Relationships_API::register( [
            'id'   => 'post-to-page',
            'from' => [
                'object_type' => 'post',
                'post_type'   => 'post',
                
            ],
            'to'   => [
                'object_type' => 'post',
                'post_type'   => 'page',
                'field'       => [
                    'query_args' => [
                        'post_status' => array( 'publish', 'draft' )
                    ],
                ],
            ],
        ] );
    }

    Refer to MB Relationships documentation https://docs.metabox.io/extensions/mb-relationships/#syntax
    and WordPress query https://developer.wordpress.org/reference/classes/wp_query/#status-parameters

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.