Why “Warning: Invalid argument supplied for foreach()”

According to the documentation, get_the_terms() returns an array of WP_Term objects, or a boolean false value, or a WP_Error object. The last two won’t work with foreach(). You could update your code to check for these conditions: $orgs_in_post = get_the_terms($post[‘ID’], ‘company’); if ( is_array( $orgs_in_post ) ) { foreach ($orgs_in_post as $org_single) { array_push($recent_companies, $org_single->term_id); … Read more

How do I get array of types associated with a taxonomy?

You’re using the correct code (get_taxonomy(‘dog’)->object_type) or function, but it should only be used after the taxonomy has been registered. Otherwise, the function would return a false instead of a proper taxonomy object which contains properties like object_type which is an array of post types registered for the taxonomy. And because taxonomies are normally (or … Read more

Custom query to filter posts that have current post as a taxonomy [closed]

I made it through! I’ll share how I did in case some other person lacking the php knowledge like me lands in the same spot. add_action(‘elementor_pro/posts/query/projects_designs_query’, function($query) { $post_id = get_the_ID(); $meta_query[] = [ ‘post_type’ => ‘designs’, ‘taxonomy’ => ‘projects’, ‘value’ => $post_id, ‘compare’ => ‘in’, ]; $query->set( ‘meta_query’, $meta_query ); } ); What this … Read more

Set post terms on post publish

The argument from pending_to_publish action, $post_id in your case, is not ID but array (callback to publish). I think it would be better to use the publish_post action, that way $post_id will actualy be the post id. Also this is a very general action so if you have multiple post types it would be wise … Read more

Redirect parent taxonomy to it’s child

Assuming state and city are variable path segments, so you are essentially redirecting /investments/<one>/<two>/ to /investments/<two>/ then try the following at the top of your .htaccess file: # Redirect “/investments/<one>/<two>/” to “/investments/<two>/” RewriteRule ^(investments)/[^/]+/([^/]+)/$ /$1/$2/ [R=302,L] If you need any further explanation then just ask in comments. UPDATE: I’ve added an end-of-string anchor ($) to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)