MB Block Not Searching Attachments?

Support MB Blocks MB Block Not Searching Attachments?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #43875
    Andrew TegenkampAndrew Tegenkamp
    Participant

    I have a field defined as this:

    		'fields' => [
    			[
    				'id'   => 'vpp_post',
    				'type' => 'post',
    				'name' => 'Post or Page?',
    				'post_type' => ['post','page','attachment'],
    			],
    		],
    

    It works well to search posts and pages, but not attachments/media. My Media Library may be considered large, as it is over 1500 items and growing if that matters. Is there any way to debug this or did I get something wrong in post_type? I got attachment from the Online Generator at https://metabox.io/online-generator/ and selecting "Post" and changing the Post types to media. The docs at https://docs.metabox.io/fields/post/#enabledisable-ajax-requests seem to indicate that can be an array and that works great for posts and pages but I'm really hopeful to have all 3 for this block.

    Thanks.

    #43883
    PeterPeter
    Moderator

    Hello Andrew,

    I also see that issue on my site and I've escalated this issue to the development team to fix it in the next update of the Meta Box plugin.

    Thank you.

    #43914
    Andrew TegenkampAndrew Tegenkamp
    Participant

    Thanks. I see it does work when I add query_args and post_status of inherit since Media files use Inherit instead of Publish by default. This seems to get me what I want as it looks like the WP_Query loop knows to only get the most recent Post/Page and not all the inherited revisions.

    
    'fields' => [
    	[
    		'id'   => 'vpp_post',
    		'type' => 'post',
    		'name' => 'Post or Page?',
    		'post_type' => ['post','page','attachment'],
    		'field_type'  => 'select_advanced',
    		'query_args'  => [
    			'post_status'    => ['publish','inherit'],
    			'posts_per_page' => - 1,
    		],
    	],
    ],
    

    I'm not sure if updating the code to work without the query_args is the right answer, or updating the docs, but I'll let you and the devs work that out 🙂

    Thanks again for taking a look!
    Andrew

    #43930
    PeterPeter
    Moderator

    Hello,

    Thanks for sharing the information.

    Following the WordPress documentation, the attachment post (media) could be considered a child of a post so you can use the post_status inherit or any to get the attachment posts.
    https://developer.wordpress.org/reference/functions/get_children/
    https://wordpress.org/documentation/article/post-status/

    I will inform the development team to update the doc for this case.

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