Search post by post meta with rest api.

Use filter rest_{$this->post_type}_query to add the post meta support in WP Rest API.

Use below code snippet to add the post meta support for post type Post.

Syntax:

http://mysite.com/wp-json/wp/v2/post?meta_key=<meta-key>&meta_value=<meta-value&gt;

How to use?

E.g. Get posts which post meta already-visited value is true.

http://mysite.com/wp-json/wp/v2/post?meta_key=already-visited&meta_value=true

Code Snippet:

Getting curl to output HTTP status code?

A more specific way to print out just the HTTP status code is something along the lines of:

Command:
curl -s -o /dev/null -w "%{http_code}" https://wordpress.org/

Output:
200

E.g.

Create a simple shortcode in WordPress

Use code snippet to create a simple WordPress shortcode. I have created a sample shortcode prefix-portfolio with 2 attributes.

Before use change:

  • Change the Prefix with your own unique prefix.
  • Change the prefix with your own unique prefix.

How to use?

  1. Create a new page and add shortcode.
  2. Open the page. It’ll show the output of the shortcode like below:

Code Snippet

Debug WordPress hook sequence

Debug WordPress hook sequence

How it works?

Add query parameter debug in URL e.g. https://<mysite>/?debug. It’ll show the list of hooks in sequence.

Code Snippet

Register or Enqueue Google fonts in WordPress Theme

A valid way to register the Google fonts in the theme or plugin.

Individual site upload limit notice

Show individual site upload limit notice on media page WordPress (Only for Multisite)

Eg.

Snippet

Add post meta in post (custom post type) endpoint with Rest API

Add post meta in post (custom post type) endpoint with Rest API.

Todo:

  • Change post-type with your post type slug.
  • Change prefix-meta-key with your post meta key which you want to include in Rest API Response.

Output:

Visit https://<mysite>/wp-json/wp/v2/<post-type>/ it show the stored data from meta key  prefix-meta-key in the Rest API response.

Code: