Hello Iuliasro,
can you write me in more details what you do.
And what your problem is?
Because I have no problems and can’t comprehend your issue.
I do like it is described here: https://codex.ww.wp.xz.cn/Class_Reference/WP_Query#Category_Parameters
– How many categories have you assigned to one post?
– How many categories do you have?
– Which PHP version do you use (on the server)?
– Which WordPress version do you use?
– (Can you write me your Theme name?)
Hi,
Sorry for not giving more details.
The args should be:
$query = new WP_Query( array( ‘cat’ => 4 ) );
but they are in your code:
$query = new WP_Query(array(‘cat’ => array( ‘cat’ => 4 ) ));
this is the exact copy from your code:
$args = array(
‘cat’ => array( ‘cat’ => $category),
‘category__not_in’ => $exclude_categories,
‘post__not_in’ => array( $exclude_current_post ),
‘showposts’ => isset($instance[‘num’])?$instance[‘num’]:0, // Number of same posts that will be shown
‘ignore_sticky_posts’ => 1,
‘orderby’ => $sort_by,
‘order’ => $sort_order
);
The problem was that the posts were not pulled from the same category, the category was ignored. I corrected that line and now the posts are pulled from the correct category. It is a small problem probably from your latest update and I just wanted to warn you about it.
I have a custom theme, wordpress 4.2.2
Thank you for your response.
Hello Iuliasro,
I found a bug and fix it on GitHub: https://github.com/DanielFloeter/same-category-posts
Are you familair with GitHub? Because you can download the code there (https://github.com/DanielFloeter/same-category-posts) and copy the files to your plugin folder ([your-wp-installation]/wp-content/plugins/same-category-posts) to your wordpress installation or upload the downloaded ZIP file with WordPress (Dashboard > Plugins > Installed Plugins > “Add New” button > “Upload Plugin” button >)
Can you give me a short feedback, if the code works for you?
Greetings
Daniel