Try this instead:
$posts_with_category = new WP_Query( $args );
if( $posts_with_category->have_posts() ) {
Instead of just checking if $posts_with_category
is non-empty it checks if it’s an array of WP_Post
objects.
We don’t have line numbers to see where the error is being thrown. Is line 47 your return statement?
Related Posts:
- get_the_content if it contains multiple lines it results in SyntaxError
- Prevent post from being published and show error
- How to update custom fields using the wp_insert_post() function?
- Should I use spl_autoload_register() in my plugin?
- WP-CLI – Selecting PHP version
- error_log() output for print_r() appearing on page
- Disable Attachment Pages Completely
- When to use Exceptions vs Error Objects vs just plain false/null
- Inject post (from specific category) between posts in Loop
- Hide php Notices in Dashboard
- PHP Catchable fatal error: Object of class WP_Error could not be converted to string
- Upgrading PHP version results in “Use of undefined constant WP_CONTENT_DIR” warning?
- WSOD but WP_DEBUG not giving any errors
- Remove option to allow trackbacks/pingbacks from post page options
- WordPress “Link has expired” error on updating posts
- Display posts by month
- Custom SQL query to get List of posts with featured image url
- Alter query on edit.php
- Permanently remove first image from posts
- How to get year, month and hour in WordPress?
- Handling error states with admin_post
- Looking to exclude blog posts from category Previous/Next buttons
- Insert code when users come from an specific referer
- Handling an Ajax form submit
- Notice: Constant already defined in wp-config.php on (non-existent) line?
- Automatic Excerpt Not Working
- How to display related posts from parent category
- How to resolve error “Cookies are blocked due to unexpected output.”?
- error_log is not working as expected in functions.php file
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- Enable errors PHP WordPress 5.2
- “Can’t use function return value in write context” error
- Fatal error: Call to undefined function wpsc_cart_item_count()
- Why when I instantiate wp_error in a validation method my user registration method stops working?
- Using a javascript file to access a get posts array
- Error when requesting password reset email – wp authentication
- Go to / Scroll to Password Field on WordPress Posts After Submit With Message(s)
- “Notice: Undefined variable: content” is showing [closed]
- New Plugin Review
- Make custom field meta not display if there is not data in it
- Print number of post (in reverse)
- Use template for posts with a particular category grandparent
- After upgrading to PHP 7.0 my contact form outputs error
- Count number of published posts by type
- WP Insert Post function – Insert Post Thumbnail
- Automatically generate Post/Page from searched Database item?
- How to migrate the posts from an old custom legacy blog to a new WordPress website?
- How is WordPress manipulating the posts like there are folders?
- Does WordPress have a built in reference to the PHP version its running under? [closed]
- Get_the_author doesn’t return author name
- Styling images coming from another blog
- Can WordPress email the admin about PHP errors, while hiding them from the site?
- Get taxonomy terms only of the WP_Query current posts
- Exclude posts from homepage having a specified tag
- How to get 2 or multiple custom post types in wordpress functions.php
- “before delete post” action fire when the post is updated?
- White Screen of Death – wp-admin
- Ajax return code 400
- Displaying a button on each post
- Trying to make php run in a post
- Hide post if matches current month and year
- Creating bulk posts with Youtube videos
- Remove posts after a given amount of time
- Automatically add custom CSS to new posts using a category template
- How Display Posts on category
- Hide wordpress field if data is empty in post!
- How can I use wp_query to show all product data using just the products ID?
- Query all posts of a custom taxonomy term
- Retrieving Author ID in wp-admin area
- WordPress 5 WP REST routes – No errors
- Getting a specific post values to another div or modal
- Trying to add attribute to my posts’ featured image
- Displaying the last post on static homepage
- Can’t get wp_insert_post to work
- Why not yield/iterable in posts interface?
- How to find error in my code when the error message is pointing to WP core file?
- Best practice for migration friendly images in posts/pages?
- get_term_link() returns correct – But illogical error-messages disturb
- How to show part of the_content?
- Posts sortable column not sorting properly for custom field numbers
- Troubleshooting “loopback requests that take too long”
- Data inserted in database, but ajax calls error function
- WordPress article with 50 000 words loading slow – 100% cpu
- link to page_for_posts
- Parse error: syntax error, unexpected ‘}’ in C:\wamp64\www\Proiect\aplicatie\user_check.php on line 18 [closed]
- Display post of specific category on page
- HOW TO Insert Existing PHP Code to WOrdPress
- Query posts by custom fields (object post)
- Query Concatenation
- WP Debug enabled Undefined index error in a widget
- php 7.0 update to 7.1 and at least 7.2
- How to modify this function to exclude also the post belonging to a specific category?
- What does that mean: cannot use a scalar value as an array [closed]
- problem with php function error
- How to handle PHP parse errors?
- How to customize posts in WordPress by using HTML and CSS?
- How to display the date under the post title?
- PHP warning Invalid argument supplied for foreach() on custom page template
- foreach all the post
- How to list all the posts in a personalized page? WordPress