Skip to content

Commit

Permalink
Use WP_Query instead of direct query
Browse files Browse the repository at this point in the history
  • Loading branch information
aulisius committed Aug 3, 2022
1 parent dc14ecf commit 3d40b82
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
42 changes: 23 additions & 19 deletions includes/RestApi/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,30 @@ class UserController {
protected $rest_base = '/user';

public function register_routes() {
\register_rest_route(
$this->namespace,
$this->rest_base . '/page-status',
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( $this, 'get_page_status' ),
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ),
),
)
);
}
\register_rest_route(
$this->namespace,
$this->rest_base . '/page-status',
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( $this, 'get_page_status' ),
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ),
),
)
);
}

public function get_page_status() {
global $wpdb;
return $wpdb->get_results(
$wpdb->prepare(
"select post_id, meta_value from wp_postmeta where meta_key LIKE 'nf_dc_page'")
);
}
public function get_page_status() {
$args = array(
'posts_per_page' => 3,
'post_type' => 'page',
'meta_key' => 'nf_dc_page',
'meta_value' => array('home', 'about', 'contact'),
'meta_compare' => 'IN'
);
$query = new \WP_Query( $args );
return $query->get_posts();
}

/**
* Connect to UAPI with token via AccessToken Class in Bluehost Plugin
Expand Down
2 changes: 1 addition & 1 deletion src/components/CustomizeStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function CustomizeStore(props) {
let { data: pluginsOnSite } = useSWR("/newfold-ecommerce/v1/plugins/status");
let { data: postsMeta } = useSWR("/newfold-ecommerce/v1/user/page-status");
let postsByName = Object.fromEntries(
postsMeta?.map((_) => [_["meta_value"], _["post_id"]]) ?? []
postsMeta?.map((_) => [_["post_name"], _["ID"]]) ?? []
);
return (
<DashboardContent
Expand Down

0 comments on commit 3d40b82

Please sign in to comment.