php - Enforcing posts per page specified in WordPress settings
Get the solution ↓↓↓Problem is that despite specifying "posts per page" to be 9 in WordPress settings area,
WordPress is NOT counting the post that is injected by the awesome plugin below,
therefore my website will display a total of 10 posts (9 posts plus 1 injected post).
How can I make WordPress count the injected post?
-My posts are displayed in a 3 column layout.
-I am using the plugin below to inject a post from a specific category called "sponsor".
-In WordPress admin area > Settings > Reading > I set "posts per page" to be 9.
This matters because if I have 2 posts in the category "sponsor" that I want to inject,
then page 1 will display the first sponsored post,
and page 2 will display the second sponsored post,
but page 3 and beyond will display nothing (which is correct because there are no more "sponsor" posts)
so the layout will show empty space.
.
Workaround that did not work
Using $paged and changing posts_per_page for $paged < 3 caused the plugin to NOT properly work. It would not display injected post for page 2. See $paged code here
.
Problem: Need WordPress to count the post (injected by the plugin)
X represents my posts
O represents sponsored posts injected by the plugin
If I have 2 posts in "sponsor" category, page 3 and beyond will not have a "sponsor" post to inject so will have empty space:
Page 1 Page 2 Page 3
X X X X X X X X X
X X X X X X X X X
X O X X O X X X
Plugin
Click Here for the Github plugin code.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: illuminate\http\exceptions\posttoolargeexception
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.