Skip to content

Commit

Permalink
Changed some query-related code to prevent interference with other pl…
Browse files Browse the repository at this point in the history
…ugins
  • Loading branch information
matthiassiegel committed May 13, 2012
1 parent acb3dcb commit f268cf7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
11 changes: 8 additions & 3 deletions README.md
@@ -1,19 +1,19 @@
Related Related
======= =======


A simple 'related posts' plugin that lets you choose the related posts yourself instead of generating the list automatically. A simple 'related posts' plugin that lets you select related posts manually instead of automatically generating the list.


Tested on WordPress 2.9 - 3.2.1 Tested on WordPress 2.9 - 3.2.1


Websites: Websites:


* [http://wordpress.org/extend/plugins/related/](http://wordpress.org/extend/plugins/related/) * [http://wordpress.org/extend/plugins/related/](http://wordpress.org/extend/plugins/related/)
* [http://chipsandtv.com/articles/wordpress-related-posts](http://chipsandtv.com/articles/wordpress-related-posts) * [https://github.com/matthiassiegel/Related](https://github.com/matthiassiegel/Related)


Description Description
----------- -----------


A simple 'related posts' plugin that lets you choose the related posts yourself instead of generating the list automatically. Supports any post types in WordPress, including custom ones. A simple 'related posts' plugin that lets you select related posts manually instead of automatically generating the list. Supports any post types in WordPress, including custom ones.


Features: Features:


Expand Down Expand Up @@ -131,7 +131,12 @@ If you're a developer you are encouraged to submit improvements. Just fork it an
Changelog Changelog
--------- ---------


### 1.11wip

* Minor rewrites that may prevent interference with other plugins

### 1.1 ### 1.1

* Bugfix: related posts are now correctly saved (deleted) when all related posts are removed from the current post * Bugfix: related posts are now correctly saved (deleted) when all related posts are removed from the current post
* Feature: all post types in WordPress are now supported (including custom ones) * Feature: all post types in WordPress are now supported (including custom ones)
* Improvement: select box now sorts posts by title and displays post type * Improvement: select box now sorts posts by title and displays post type
Expand Down
9 changes: 6 additions & 3 deletions readme.txt
@@ -1,16 +1,16 @@
=== Related === === Related ===
Contributors: chipsandtv Contributors: chipsandtv
Donate link: http://chipsandtv.com/ Donate link: https://github.com/matthiassiegel/Related
Tags: related posts, related, post Tags: related posts, related, post
Requires at least: 2.9 Requires at least: 2.9
Tested up to: 3.2.1 Tested up to: 3.2.1
Stable tag: trunk Stable tag: trunk


A simple 'related posts' plugin that lets you choose the related posts yourself instead of generating the list automatically. A simple 'related posts' plugin that lets you select related posts manually instead of automatically generating the list.


== Description == == Description ==


A simple 'related posts' plugin that lets you choose the related posts yourself instead of generating the list automatically. Supports any post types in WordPress, including custom ones. A simple 'related posts' plugin that lets you select related posts manually instead of automatically generating the list. Supports any post types in WordPress, including custom ones.




Features: Features:
Expand Down Expand Up @@ -125,6 +125,9 @@ If you're a developer you are encouraged to submit improvements. Just fork it on


== Changelog == == Changelog ==


= 1.11wip =
* Minor rewrites that may prevent interference with other plugins

= 1.1 = = 1.1 =
* Bugfix: related posts are now correctly saved (deleted) when all related posts are removed from the current post * Bugfix: related posts are now correctly saved (deleted) when all related posts are removed from the current post
* Feature: all post types in WordPress are now supported (including custom ones) * Feature: all post types in WordPress are now supported (including custom ones)
Expand Down
19 changes: 11 additions & 8 deletions related.php
@@ -1,14 +1,14 @@
<?php <?php
/* /*
Plugin Name: Related Plugin Name: Related
Plugin URI: http://chipsandtv.com/ Plugin URI: https://github.com/matthiassiegel/Related
Description: A simple 'related posts' plugin that lets you choose the related posts yourself instead of generating the list automatically. Description: A simple 'related posts' plugin that lets you select related posts manually instead of automatically generating the list.
Version: 1.1 Version: 1.1
Author: Matthias Siegel Author: Matthias Siegel
Author URI: http://chipsandtv.com/ Author URI: https://github.com/matthiassiegel/Related
Copyright 2010-2011 Matthias Siegel (email: chipsandtv@gmail.com) Copyright 2010-2012 Matthias Siegel (email: matthias.siegel@gmail.com)
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -48,7 +48,7 @@ public function __construct() {
protected function defineConstants() { protected function defineConstants() {


define('RELATED_VERSION', '1.1'); define('RELATED_VERSION', '1.1');
define('RELATED_HOME', 'http://chipsandtv.com/'); define('RELATED_HOME', 'https://github.com/matthiassiegel/Related');
define('RELATED_FILE', plugin_basename(dirname(__FILE__))); define('RELATED_FILE', plugin_basename(dirname(__FILE__)));
define('RELATED_ABSPATH', str_replace('\\', '/', WP_PLUGIN_DIR . '/' . plugin_basename(dirname(__FILE__)))); define('RELATED_ABSPATH', str_replace('\\', '/', WP_PLUGIN_DIR . '/' . plugin_basename(dirname(__FILE__))));
define('RELATED_URLPATH', WP_PLUGIN_URL . '/' . plugin_basename(dirname(__FILE__))); define('RELATED_URLPATH', WP_PLUGIN_URL . '/' . plugin_basename(dirname(__FILE__)));
Expand Down Expand Up @@ -105,12 +105,14 @@ public function save($id) {
// Creates the output on the post screen // Creates the output on the post screen
public function displayMetaBox() { public function displayMetaBox() {


global $post_ID; global $post;

$post_id = $post->ID;


echo '<div id="related-posts">'; echo '<div id="related-posts">';


// Get related posts if existing // Get related posts if existing
$related = get_post_meta($post_ID, 'related_posts', true); $related = get_post_meta($post_id, 'related_posts', true);


if (!empty($related)) : if (!empty($related)) :
foreach($related as $r) : foreach($related as $r) :
Expand All @@ -132,7 +134,7 @@ public function displayMetaBox() {


$query = array( $query = array(
'nopaging' => true, 'nopaging' => true,
'post__not_in' => array($post_ID), 'post__not_in' => array($post_id),
'post_status' => 'publish', 'post_status' => 'publish',
'posts_per_page' => -1, 'posts_per_page' => -1,
'post_type' => 'any', 'post_type' => 'any',
Expand All @@ -151,6 +153,7 @@ public function displayMetaBox() {
endif; endif;


wp_reset_query(); wp_reset_query();
wp_reset_postdata();


echo ' echo '
</select> </select>
Expand Down
24 changes: 12 additions & 12 deletions styles.css
@@ -1,18 +1,18 @@
.related-post { .related-post {
font-size: 11px; font-size: 11px;
margin: 6px 6px 8px; margin: 6px 6px 8px;
padding: 8px; padding: 8px;
background: #f1f1f1; background: #f1f1f1;
border: 1px solid #dfdfdf; border: 1px solid #dfdfdf;
cursor: pointer; cursor: pointer;
border-radius: 4px; -webkit-border-radius: 4px;
-webkit-border-radius: 4px; -moz-border-radius: 4px;
-moz-border-radius: 4px; border-radius: 4px;
} }
.related-post-title { .related-post-title {
padding: 0 30px 0 0; padding: 0 30px 0 0;
} }
.related-post a { .related-post a {
float: right; float: right;
} }

0 comments on commit f268cf7

Please sign in to comment.