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
- Should I use spl_autoload_register() in my plugin?
- WP-CLI – Selecting PHP version
- Disable Attachment Pages Completely
- Inject post (from specific category) between posts in Loop
- Hide php Notices in Dashboard
- Upgrading PHP version results in “Use of undefined constant WP_CONTENT_DIR” warning?
- Remove option to allow trackbacks/pingbacks from post page options
- How to get year, month and hour in WordPress?
- Handling an Ajax form submit
- Fatal error: Call to undefined function wpsc_cart_item_count()
- Print number of post (in reverse)
- After upgrading to PHP 7.0 my contact form outputs error
- Count number of published posts by type
- Automatically generate Post/Page from searched Database item?
- Get taxonomy terms only of the WP_Query current posts
- How to get 2 or multiple custom post types in wordpress functions.php
- Displaying a button on each post
- Hide post if matches current month and year
- Creating bulk posts with Youtube videos
- Automatically add custom CSS to new posts using a category template
- How Display Posts on category
- Getting a specific post values to another div or modal
- How to find error in my code when the error message is pointing to WP core file?
- PHP Warning: Attempt to read property “term_id” on bool
- Unreadable pagination
- how do I get a specific post from a post with a subcategory in WP
- Mute Debug Messages from Plugins
- Error on wp_default_style After upgrade to php 7
- Open post-content in archive page in a Modal box with bootstrap
- remove post that has no content
- How to show only subcategories in parent category not parent category?
- Error: options page not found
- Which is the correct way to conditionally enqueue a CSS file?
- WP Insert Post and then go to post
- Get latest post from all categories except one
- Parse error: syntax error, unexpected end of file
- customize wordpress database error page
- Automatically add images to a menu
- Load Posts on Click via Ajax into a DIV
- Store metakey value as an array
- After adding my website to a new server, I keep getting a unexpected end of file error, but the file is identitcal to it’s original source
- Only show first image in foreach loop
- create front-end users post list by specific category
- show recent posts php code error?
- Error display post thumbnails for previous and next post
- Post to WordPress from another Server via PHP
- form $_post action value gets truncated after it passes through two forms
- Wrap posts p tags in div
- Wp Query : Order by distance lat,lon
- Add posts to custom table in database instead of wp_posts
- get value from get_post_meta then reuse it in another get_post_meta
- Illegal string offset in PHP function in via Theme Customizer
- Generating 10 000 WordPress posts using PHP and avoiding Server Timeout error
- If Post Published Date or Modified Date is 1 Year or Older, Display Notice on Post Page
- WordPress Post Block Element not properly parsed with the_content filter
- Filter wordpress posts without searching the keywords in the post content
- Build A Custom SQL Query for WordPress Search
- WordPress Custom Form – Getting Query Vars, Weird Glitch?
- Cannot find the php_ini configuration file to find my error log to see why my code is not working
- How to Send Pingbacks for all Posts in WordPress?
- I am having errors with checkout on wordpress
- Display articles with a different template in the home page | Solved |
- How can I check if a post with a particular slug or title exists?
- WordPress sorting posts by date and title using a dropdown
- Intermittent 503 Service Unavailable Error
- How to get post titles by post ID and integrate with my code?
- Trying to get post ID outside loop on blog page
- Infinite looping next post link within a certain category on a post
- Enqueue script only on child pages of custom post types
- Attach and retrive multiple pdf files to post or page
- Get list of posts from attachment
- How to use a PHP file to control the content of a blog post
- When working with a post, almost all wp_postmeta are deleted
- Displaying POST content with HTML tags and all
- Pagination in WP Queries
- WordPress 3.0 PHP Error – notice WordPress_product_Type was called incorrectly
- Using Tag Groups: Displaying groups and adjacent tags of current post
- Add div after every 4 posts then every 2 posts for a responsive loop
- Only display notification on single post
- Display 6 most recent post on homepage?
- Only Get A Certain Number of Posts From WP_Query
- Apply filters when loading post via ajax
- Can’t put a hyperlink on Featured Post’s Image
- How to call post title and post summary to other part of site?
- Published custom posts missing
- WordPress get_post_meta issue
- Display pages from specific page template
- Add Custom Post Type on the Fly or create an array
- WordPress article with 50 000 words loading slow – 100% cpu
- Display post of specific category on page
- problem with php function error
- How to display the date under the post title?
- WooCommerce: write featured image dimensions to custom fields in product’
- Getting invalid user ID error when creating a new user with wp_insert_user
- transition_post_status hook, works – but not if the post is new
- Error when loading Dashboard
- PHP Warning: Undefined array key “VirtualHostSubMenu” in index.php
- Display two previous posts on single.php