Advertisement

WordPress Rest API Get specific posts by IDs by using `include` parameter

With the Rest API we get all the posts. But, Sometimes we want to get only specific posts by post ids. WordPress have rest API parameter include which return only requested posts by post ids. Syntax https://example.org/wp-json/wp/v2/posts?include=<post-ids> Example https://example.org/wp-json/wp/v2/posts?include=11,12 It return only 2 posts whose ids are 11 & 12. Note: By default it return 10

WP CLI Commands

WP-CLI is the command-line interface for WordPress. You can update plugins, configure multisite installs, and much more, without using a web browser. Below is the complete list of WP CLI commands generated with WP CLI Commands Cheat Sheet (Complete List of WP CLI Commands) Cache wp cache add Docs | Git wp cache decr Docs | Git

Search Post by Post Meta in Rest API

WordPress provides the Rest API support for post, pages and custom post types which have set the show_in_rest parameter as true. We have also the Rest API support for the tags, categories and custom taxonomies which have same show_in_rest parameter as true. Table of content Overview We have Rest API endpoints for the post &

Advertisement

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? Create a new page and add shortcode. Open the page. It’ll show the output of the

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 This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.

Individual site upload limit notice

Show individual site upload limit notice on media page WordPress (Only for Multisite) Eg. Snippet This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters <?php

Advertisement

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: This file contains bidirectional

Check logged in user role in WordPress

Check logged in user role. Use function  wp_get_current_user() to get the current/logged in user info. Usage: var_dump( prefix_user_has_role( ‘administrator’ ) ); // Output: // bool(true) Snippet: This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode

Advertisement

Streamline your web font requests. Introducing “text=”

Google Fonts provides the attribute text= for Optimizing your font requests (Beta) Helps, If you google fonts for particular texts then use it. In some cases, this can reduce the size of the font file by up to 90%. Visit: https://developers.google.com/fonts/docs/getting_started?hl=en How to Use? Checkout below example. Here, Google Fonts apply only for text “LOGO”.