An open API service indexing awesome lists of open source software.

https://github.com/xwp/wp-better-find-posts

Better Find Posts WordPress plugin
https://github.com/xwp/wp-better-find-posts

Last synced: 3 months ago
JSON representation

Better Find Posts WordPress plugin

Awesome Lists containing this project

README

          

# Better Find Posts

Extensible JavaScript-centric replacement for the WordPress 3.1 `find_posts_div()`/`findPosts`
API. Add to page via `\Better_Find_Posts::instance()->enqueue()` then create
a control via `BetterFindPosts.create()`.

Example code:

```php

add_action( 'add_meta_boxes', function () {
$id = 'linked-post-metabox';
$title = __( 'Linked Post' );
$post_type = 'post';
$context = 'normal';
$priority = 'high';
$callback = 'linked_post_metabox';
add_meta_box( $id, $title, $callback, $post_type, $context, $priority );
} );

function linked_post_metabox() {
\Better_Find_Posts::instance()->enqueue();
?>





BetterFindPosts.ready.done( function () {
var control = BetterFindPosts.create( {
searchFormContainer: '#linked-post-metabox .search-form',
resultsTableContainer: '#linked-post-metabox .results-table',
defaultQueryArgs: {
'post_type': 'post',
'post_status': 'publish'
},
hiddenColumns: [ 'type', 'status', 'time' ]
} );

// @todo Need some built-in events here

control.resultsTableContainer.on( 'click', 'input', function () {
var post_id = jQuery( this ).val();
// Do something with this
} );
} );