WordPress

Lesson 2. Developing a Shortcode for the WP Post Autocomplete Plugin
Lesson 2. Developing a Shortcode for the WP Post Autocomplete Plugin

Let’s continue developing our WP plugin for post autocomplete. Today, we will create a shortcode with an input field for the search query.

Generally speaking, there are two approaches to structuring plugin code:

  1. Use standalone functions to define hooks, filters, helpers, etc. In this case, it’s best to prefix each function name to avoid conflicts with other plugins/themes or WordPress core functions.
  2. Use class-based development. Here, you still need to use prefixes, but far fewer, since most logic is encapsulated in class methods.

read more...

Lesson 1. How to write a WordPress plugin yourself.
Lesson 1. How to write a WordPress plugin yourself.

With this post, I’m starting a series of complementary articles dedicated to developing plugins for WordPress. The goal of our plugin will be to implement AJAX-based post search with autocomplete. To achieve this functionality, we’ll need to cover several topics, including:

  1. Plugin file creation
  2. Shortcode development
  3. Connecting styles and scripts
  4. Working with AJAX in WordPress
  5. Using jQuery Autocomplete
  6. Displaying post lists on the page and adding pagination

As you can see, there’s a lot of work ahead. For those just starting out with WordPress development, this should be especially useful.

read more...

How to Create Your Own Status Post in WordPress
How to Create Your Own Status Post in WordPress

Why do we need custom statuses? As always, there are many use cases. I personally used them only once — to mark products that didn’t fall into any category when importing from the Yandex Market.

Below is an example of creating a custom post status. More about all the parameters can be found in the official WordPress Codex. I just want to highlight the following points:

  1. The "label_count" parameter must be defined using the "_n_noop()" function.
  2. Unfortunately, custom statuses are not automatically shown on the post edit/create page or in the post list table (when hovering over the post title to see quick actions).

read more...

How to display posts sorted by latest comments in WordPress
How to display posts sorted by latest comments in WordPress

WordPress (WP) has a universal function called `get_posts`, but unfortunately, it doesn’t work in 100% of cases. Sometimes, to get the desired result, you need to manually build an SQL query. I don’t really like doing that, since I don’t know all the ins and outs of WP’s internal mechanisms (such as where and when certain filters should be applied). But when the task requires it, you have to write custom SQL.

read more...

How to Change the Link Set in WordPress Meta Widget
How to Change the Link Set in WordPress Meta Widget

WordPress has a built-in widget by default called “Meta”. The functionality of this widget is quite simple. It displays a set of links that change dynamically depending on the user's login status. That is, whether the user is logged in or not. This widget displays the following links — site admin (or registration), login (or logout), post RSS, comment RSS, and WordPress.org.

In one of my projects, I needed to limit the number of links in the menu. I wanted to keep only the first two — registration and login — and remove the other three — RSS + WP — as unnecessary.

read more...