Skip to content

Commit 8b2a39e

Browse files
committed
notes
1 parent 4a03ccc commit 8b2a39e

File tree

2 files changed

+13
-60
lines changed

2 files changed

+13
-60
lines changed

index.php

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
11
<?php
2-
/**
3-
* @package Unique_WP_Query
4-
* @version 1.0.0
5-
*/
62
/*
73
Plugin Name: Unique WP Query
84
Plugin URI: https://github.com/firstandthird/unique_wp_query
95
Description: A plugin for doing unique WP_Query
106
Author: firstandthird
117
Version: 1.0.0
12-
*/
13-
// adapted & taken from from https://gist.github.com/jameswburke/d0776d742ab74c469cd8af8dacd916fc
14-
15-
/**
16-
* Wrapper for WP_Query
17-
* Interacts directly with WP_Query_Manager to ensure
18-
* only unique posts are ever returned.
19-
*
20-
* Known issues:
21-
* Won't work with offset values
8+
// adapted & taken from https://gist.github.com/jameswburke/d0776d742ab74c469cd8af8dacd916fc
229
*/
23-
class Unique_WP_Query extends WP_Query {
10+
11+
class Unique_WP_Query extends WP_Query {
2412
function __construct($args) {
2513
// Act as a flag for pre_get_posts
2614
$args['unique_wp_query'] = true;
@@ -30,11 +18,14 @@ function __construct($args) {
3018
foreach ($args['post__not_in'] as $key => $id) {
3119
Unique_WP_Query_Manager::add_post_id($id);
3220
}
21+
unset($args['post__not_in']);
3322
}
3423

3524
// don't get the current post or page:
36-
$id = get_the_ID();
37-
Unique_WP_Query_Manager::add_post_id($id);
25+
if (is_single()) {
26+
$id = get_the_ID();
27+
Unique_WP_Query_Manager::add_post_id($id);
28+
}
3829

3930
// Initialize the WP_Query object like normal
4031
parent::__construct($args);
@@ -145,10 +136,9 @@ public static function process_posts(&$posts, &$post_count, $original_posts_per_
145136
function unique_wp_query_pre_get_posts(&$query) {
146137
if (true === $query->get('unique_wp_query')) {
147138
$posts_per_page = $query->get('posts_per_page');
148-
149-
// Increase posts_per_page by the amount of used post_ids
150-
$query->set('original_posts_per_page', min($posts_per_page, 200));
151-
$query->set('posts_per_page', min($posts_per_page + Unique_WP_Query_Manager::$used_post_count, 200));
139+
// Increase posts_per_page by the amount of used post_ids
140+
$query->set('original_posts_per_page', min($posts_per_page, 200));
141+
$query->set('posts_per_page', min($posts_per_page + Unique_WP_Query_Manager::$used_post_count, 200));
152142
}
153143
}
154144

test_theme/style.css

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,3 @@
11
/*
2-
Theme Name: SharpEdge
3-
Theme URI: http://localhost:85/wordpress/themes/sharpEdge
4-
Version: 0.1
5-
Author: Vincy
6-
Author URI: https://phppot.com/
7-
Description: A Minimal WordPress Theme.
8-
Tags: minimal, simple, responsive, light-weight
9-
Text Domain: sharpEdge
10-
*/
11-
a {
12-
color: #A0A0A0;
13-
text-decoration: none;
14-
}
15-
#inner {
16-
width: 778px;
17-
text-align: left;
18-
}
19-
#contentArea {
20-
border-top: #CCCCCC 2px solid;
21-
overflow:hidden
22-
}
23-
#mainContent {
24-
float:left;
25-
width: 70%;
26-
}
27-
#sidebar {
28-
float: right;
29-
width: 28%;
30-
padding-left: 3px;
31-
padding-bottom:100%;
32-
margin-bottom:-100%;
33-
background-color: #DDDDDD;
34-
}
35-
#footer {
36-
clear:both;
37-
padding: 2px;
38-
color: #DDDDDD;
39-
background-color: #000000;
40-
}
2+
Theme Name: Test Theme
3+
*/

0 commit comments

Comments
 (0)