Author:
erics, October 13th, 2020
The first query gets all custom publication posts that have a value in field book_seq ordered by book_seq The second query gets all custom publication posts that have no meta value for book_seq or no meta record for key book_seq ordered by post_title.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
$querytop = get_posts(array( 'post_type' => 'publication', 'numberposts' => -1, 'orderby' => 'meta_value', 'meta_key' => 'book_seq', 'order' => 'ASC', 'meta_query' => array( // meta query takes an array of arrays, watch out for this! array( 'key' => 'book_seq', 'value' => array('', 'NULL'), 'compare' => 'NOT IN' ) ) )); $querybottom = get_posts(array( 'post_type' => 'publication', 'numberposts' => -1, 'orderby' => 'post_title', 'order' => 'ASC', 'meta_query' => array( // meta query takes an array of arrays, watch out for this! 'relation' => 'OR', array( 'key' => 'book_seq', 'compare' => 'NOT EXISTS' ), array( 'key' => 'book_seq', 'value' => array('', 'NULL'), 'compare' => 'IN' ) ) )); $store_query = array_merge($querytop, $querybottom); |
Great article here: https://rudrastyh.com/wordpress/meta_query.html
Categories: How-To's, Technology Tags: get_posts, meta_query, Or, php, Query, search, Store, WordPress
|
No comments
Author:
erics, September 12th, 2019
Needed to build a feature for a Bookstore tool to have an optional sequence number for the Custom Post Type “books” that would allow items with a seq number to float to the top of the list and be sorted by seq #. The rest of the books would show underneath, sorted alphabetically.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
$querytop = get_posts(array( 'post_type' => 'books', 'numberposts' => -1, 'orderby' => 'meta_value', 'meta_key' => 'book_seq', 'order' => 'ASC', 'meta_query' => array( // meta query takes an array of arrays, watch out for this! array( 'key' => 'book_seq', 'value' => array('', 'NULL'), 'compare' => 'NOT IN' ) ) )); $querybottom = get_posts(array( 'post_type' => 'books', 'numberposts' => -1, 'orderby' => 'post_title', 'order' => 'ASC', 'meta_query' => array( // meta query takes an array of arrays, watch out for this! array( 'key' => 'book_seq', 'compare' => 'NOT EXISTS' ) ) )); $query = array_merge($querytop, $querybottom); |
Categories: How-To's, Technology Tags: bottom, Compare, cpt, Exists, Filter, Float, get_posts, howto, key, meta_key, meta_value, NOT EXISTS, NOT IN, Order, OrderBy, post_type, Query, Seq, Sequence, sort, tips, top, Value, WordPress
|
No comments
Author:
erics, May 16th, 2018
SELECT t1.id FROM tableOne t1 LEFT JOIN tableTwo t2 ON t1.id = t2.id WHERE t2.id IS NULL The “WHERE t2.id IS NULL clause” restricts the results to only those rows where the id returned from tableTwo is null. tableTwo.id will be NULL for all records from tableOne where the id is not found in tableTwo.
Categories: How-To's, Technology Tags: howto, Join, Left Join, mysql, Query, Row, Rows, select, SQL, Table, tips, Where
|
No comments
Author:
erics, August 29th, 2013
window.location.href.split(‘?’)[0]
Categories: How-To's, Technology Tags: howto, javascript, Query, Query String, tips, URL
|
No comments
Author:
erics, February 25th, 2012
This query will list the names of the reports in the database: SELECT MSysObjects.Name AS Report_Name FROM MSysObjects WHERE (((MSysObjects.Type)=-32764)) ORDER BY MSysObjects.Name; This query will list the names of the queries in the database: SELECT MSysObjects.Name FROM MSysObjects WHERE (((MSysObjects.Type)=5)); This query will list the names of the tables in the database: SELECT MSysObjects.Name […]
Categories: How-To's, Technology Tags: Access, Export, howto, MS Access, Queries, Query, Reports, tips
|
No comments
Author:
erics, October 14th, 2011
|
SELECT @rownum := @rownum + 1 AS Rank, T1.* FROM (select @rownum := 0) R, ( SELECT Category, Item, Value FROM Inventory WHERE lastUpdated = CURDATE() ORDER BY Value DESC ) AS T1 WHERE T1.Item = "Camera" |
Categories: How-To's, Technology Tags: howto, Line number, mysql, Query, Row number, Sequence number, sort, SQL, tips
|
No comments