Related Posts Fixer for Elementor
Make Elementor Posts and Loop Grid widgets show only related items from the same post type and taxonomy term as the page being viewed.
by Mueed Ullah · github.com/mueedkh/related-posts-fixer-for-elementor · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/mueedkh/related-posts-fixer-for-elementor/archive/refs/heads/main.zipMake Elementor Posts and Loop Grid widgets show only related items from the same post type and taxonomy term as the page being viewed.
- Requires: WordPress 5.5+, PHP 7.2+, Elementor Pro (for the Query ID field)
- License: GPL-2.0-or-later
- Author: MaXsoft Technologies
What it does
On any single page — a product, a portfolio item, a regular post, any post type — a rule makes the widget show only items that:
- are the same post type as the page being viewed, and
- share at least one term with that page in a taxonomy you choose.
The item being viewed is always excluded from its own list. If it has no terms in the chosen taxonomy, the widget falls back to other items of the same post type rather than rendering an empty grid.
Rules are connected to widgets through Elementor's Query ID field, so you can run as many as you like — one per widget.
Setup
- Activate the plugin and open Related Posts Fixer in the sidebar.
- Add a rule: Query ID, post type, taxonomy, item count, order by and order. Save.
- In Elementor, select the Posts or Loop Grid widget and go to Content → Query.
- Set the Query ID field at the bottom to the same value as the rule.
- Update the page and clear any caching layer.
How it works
For each saved rule the plugin registers a listener on elementor/query/{query_id}. Elementor fires that hook with the widget's WP_Query before it runs, and the rule sets post_type, post__not_in, tax_query, posts_per_page, orderby and order on it.
Nothing runs on non-singular pages, and the plugin loads no front-end CSS or JavaScript. The admin stylesheet and script load only on the plugin's own settings page.
Extending
After a rule is applied, the plugin fires:
do_action( 'rpfe_rule_applied', $query, $post, $rule );
Use it to layer extra query arguments on top of a rule:
add_action(
'rpfe_rule_applied',
function ( $query, $post, $rule ) {
if ( 'related_products' === $rule['query_id'] ) {
$query->set( 'meta_key', '_featured' );
}
},
10,
3
);
Repository layout
related-posts-fixer-for-elementor.php Bootstrap: headers, constants, activation hook
includes/class-rpfe-plugin.php Rules storage, sanitising, Elementor query hooks
includes/class-rpfe-settings.php Dashboard page, rule table, asset loading
admin/css/admin.css Settings page styles
admin/js/admin.js Rule row add/remove, taxonomy dropdowns
admin/images/ Setup screenshot used on the settings page
languages/*.pot Translation template
uninstall.php Removes stored rules on delete
.wordpress-org/ Directory assets (banner, icon, screenshots)
Everything under .wordpress-org/, plus README.md, phpcs.xml.dist and the dotfiles, is listed in .distignore and is not part of the distributed plugin zip.
Data and privacy
The plugin stores a single WordPress option, rpfe_rules. It creates no database tables and contacts no external services. Deleting the plugin removes the option from every site on the network.
Coding standards
composer global require wp-coding-standards/wpcs phpcompatibility/phpcompatibility-wp
phpcs --standard=phpcs.xml.dist
Changelog
1.0.0
- Initial release.