2017 © Pedro Peláez
 

wordpress-plugin quick-query

Quick-Query is a WordPress plugin that provides a jQuery-like interface for querying posts and other information.

image

pkarl/quick-query

Quick-Query is a WordPress plugin that provides a jQuery-like interface for querying posts and other information.

  • Tuesday, November 24, 2015
  • by steyblind
  • Repository
  • 0 Watchers
  • 11 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 3 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Quick Query (alpha)

Build Status, (*1)

Quick Query is an interface for fetching data from WordPress that's intuitive and pleasant to use. It uses a jQuery-like syntax to chain together simple pieces of information and get you the right information in return., (*2)

Project Update 8-15-2014

Here are a few nuggets:, (*3)

  • As it happens, keeping the SVN version of this up to date on wordpress.org is a PITA, so until this gets to a real alpha, I'm not going to waste my energy there
    • when that does happen, I'll make sure composer + wp.org both have access to QQ
  • all posts are retrieved by default. I think Wordpress's not-so-smart defaults are something developers should be explicit about, so warm up your ppp()
  • Tests are going very well, though I had a hell of a time with Wordpress + PHPUnit and that incomplete/horribly-documented factory class. I ended up creating objects for unit tests with a combination of factory stuff, built-in wordpress functions, and a smattering of wizardry
  • Tags, taxonomy, and the like are easily the most complicated part of this. I'm nearly done with a draft that accommodates most all kinds of tax_queries, but I need to test it in combination with other WP_Query params and work on the tax() chaining interface
  • The authors, parents & children code should come very quickly after that

How it works & Background

Quick Query began as a scrap of syntactic sugar for dealing with WP_Query. Over the course of a few projects, this sugary treat grew into necessity that simplified 80% of the time-consuming query code into a few pleasant lines., (*4)

Here's an comparison in a demanding scenario:, (*5)

// The WP_Query way
$args = array(
    'post_type' => 'post',
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'movie_genre',
            'field' => 'slug',
            'terms' => array( 'action', 'comedy' )
        ),
        array(
            'taxonomy' => 'actor',
            'field' => 'id',
            'terms' => array( 103, 115, 206 ),
            'operator' => 'NOT IN'
        )
    )
);
$query = new WP_Query( $args );

// The Quick Query way
$posts = $q->type('post')->tags( ['movie_genre' => ['action','comedy'], 'actor' => [103, 115, 206]], 'AND' );

The plan

I'm working on creating an honest-to-goodness open source version of it from the ground up. At the time of this writing, Quick Query is just a class wrapper with all of our code commented out., (*6)

I'll be working on this (along with anyone who enjoys the idea of mitigating the emotional damage WP_Query causes) to incrementally re-add the functionality of QQuery along with tests and docs as we go., (*7)

TODO

  • [x] Post Type
    • $qq->type('some-type')
  • [x] Fetch Post by ID
    • $qq->get(42)
  • [x] ACF sensory
  • [x] Fetch Post in set of IDs
    • $qq->in([2, 5, 42])
  • [x] Sort order
    • $qq->sort('date', 'DESC')
  • [x] Exclude ID(s)
  • [x] Return all posts
    • $qq->all()
  • [x] Set posts per page
    • $qq->ppp(20)
  • [ ] Meta Fields options
    • $qq->meta('author')
  • [x] Pagination & Offset
    • $qq->ppp(3)->page(2)
  • [x] Filter by post status
    • $qq->status('published')
    • $qq->status(['published','draft'])
  • [ ] Terms, Taxonomies & Categories
    • $qq->term('cats')
    • $qq->tax('animals')
    • $qq->tax(['animals'=>['cats', 'dogs'], ['pizza'=>['deep', 'NYC']], 'OR')
    • $qq->category('fish')
  • [ ] Authors
    • $qq->author(1)
    • $qq->author('Pete Karl II')
  • [ ] Parents & Children
    • $qq->parent(22)
    • $qq->parent('some-slug')
    • $qq->children('some_post_type')

Needs Tests

  • ACF, see tests/test_qq_acf.php

Needs docs

(everything), (*8)

Running Tests

I recommend using 10up's VVV to set up a wordpress environment., (*9)

From there, what I've done is cloned this repo, added it as a sync'd folder in VVV's Vagrant file, and then symlinked it to my wordpress repos., (*10)

To sync any additional folder, add config.vm.synced_folder "/path/to/your/folder/", "/srv/vagrant/mirror/" to your Vagrantfile so you can edit code in your OS and run tests VM effortlessly, (*11)

To run the tests, I vagrant ssh into the vbox, navigate to the plugin directory, and run phpunit (or, more frequently, phpunit --debug), (*12)

The Versions

24/11 2015

dev-master

9999999-dev https://github.com/pkarl/quick-query

Quick-Query is a WordPress plugin that provides a jQuery-like interface for querying posts and other information.

  Sources   Download

MIT

The Requires

 

The Development Requires

database posts query context