Git Product home page Git Product logo

wp-request-posts's Introduction

wp-request-posts

Retrieve Wordpress posts from POST or GET request

Example of use

Starting from the url:
https://yourwebsite.com/?color=blue&is_promo=1&price-min=50&price-max=100

<?php

$page = !empty($_GET['p']) ? $_GET['p'] : "0";

$query = new WP_Request_Posts('products', $page); 

$builder = $query
            ->add_tax('color')
            ->add_meta('is_promo', '==')
            ->add_meta_min_max('price');
            
            
// print the args array            
$builder->debug();

            
// get the posts            
$posts = $builder->get_posts();


// get the posts count
$count = $builder->count();


// get the last page count   
$last_page = $builder->last_page();



// params:
// WP_Request_Posts: post type, page num, posts per page (default 10)

// add_tax: taxonomy, field (default: 'slug'), operator (default: 'IN')
// add_meta: key, compare (default: 'IN'), type (default: 'CHAR')
// add_meta_min_max: key, type (default: 'NUMERIC')

// If the field or the key is non available in your request,  
// the param will be simply skipped

Note

In order to use the add_meta_min_max() method, you should add the suffixes "-min" and "-max" to your inputs name.

Example:

// Meta key = 'price'

<input type="number" name="price-min" />
<input type="number" name="price-max" />

wp-request-posts's People

Contributors

marcopal avatar

Stargazers

Rihards Mantejs avatar Phillip W. avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.