wp_query_rs
A rust implementation of the classic WP_Query utility to access WordPress posts outside of a WordPress environment.
Example
If you have the environment variables setup (described below), you can use the new function to query similar to the WP_Query instance creation.
use ;
let params = new;
let wp_query = new.expect;
assert_eq!;
The prefered method of use would be to provide a connection from your own connection pool:
let params = new;
let mut con: Conn = pool.get_connection;
let wp_query = with_connection.expect;
assert_eq!;
Building Query Parameters
To add parameters to your query, chain the callbacks after ParamBuilder::new():
let params = new.posts_per_page.page;
The order of chaining is irrelevant.
Panics!
The param builder will panic if you supply illegal date parameters:
let params = new
.year
.monthnum
.day
.hour
.minute
.second; // Panics!
Inserting Posts
This package can also be used to insert posts into WordPress. This functionality uses the default connection pool initiated by this package.
let mut post = new;
let title = "My Test Post".to_string;
post.post_title = title.clone;
let post_id: u64 = post.insert.expect;
Reading and Writing Meta Data
You can also read and write metadata.
let post_id: u64 = post.insert.expect;
add_post_meta.expect;
let meta = get_post_meta;
match meta
Reading WP User Data
You can load WP User data from the database usin WpUser as well.
let user = get_user_by_id.unwrap.unwrap;
assert_eq!;
Goals
The author of this package would like to add tooling to the rust community for working with WordPress websites and data. In the future, possibly even building extensions for WordPress written in Rust to increase performance.
The building of this library itself was largely for the author's educational purposes. If there is interest in software like this I would love to work with others to improve.
Reference
The public APIs in this crate mostly model the functionality of the original WP_Query. You can see it's documentation for more information.
https://developer.wordpress.org/reference/classes/wp_query/#date-parameters
License
- Apache License, Version 2.0 (LICENSE_APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE_MIT or http://opensource.org/licenses/MIT)