Trying to put an array into ‘post__in’ => array() query not working

You need to explode the string you obtain from $_GET[‘ids’] into an array, at the moment you a parsing a to string post__in rather than an array of IDs. Try $purchaseprodid = isset($_GET[‘ids’]) ? explode(‘,’,$_GET[‘ids’]) : array(); However, you can sometimes run into difficulties using $_GET with WordPress, it’s better to use the API provided … Read more

How to extract all ID variables from a query string?

$string will contain a comma separated list of IDs: $ids = array(); foreach( $array as $post ) { if( !in_array( $post->ID, $ids ) ) { $ids[] = $post->ID; } } $string = implode( ‘, ‘, $ids ); Note: This uses basically no wordpress, other than the post object…which is really just an object.

bulk post_content update

This is what I mean: <?php $tochange = get_posts(‘numberposts=-1&post_type=any&category_name=category-name-you-want-to-change’); foreach($tochange as $post){ setup_postdata($post); $contentchange=””; /*here you do the magic, string replace or whathever you want to do*/ $tochange = array(); $tochange[‘ID’] = $post->ID; $tochange[‘post_content’] = $contentchange; $out = wp_update_post($tochange); unset($tochange); } wp_reset_query(); ?>

is_category in pre_get_posts results in php notices

is_category(‘category-name’) won’t work until after the query is run. If we check source code where those notices are generated, we can see that it’s using get_queried_object, which gets populated with the results of the main query, and at the pre_get_posts stage will still be empty. As an alternate, check the contents of $query->query_vars, which will … Read more

How to add posts to wp_query result?

Here’s a hack for the main post query in wp-admin that should do the trick: /** * Modification of the wp-admin main (post) query: * If current user has the “client” role then * show client’s posts OR posts where the “client” meta value is the client id. * * @see http://wordpress.stackexchange.com/a/173967/26350 */ function wpse_pre_get_posts( … Read more

How do I create Comma Separated list of attached image ids?

You can try this one-liner, within the loop, instead of all your above code: $ids = join( ‘,’, wp_list_pluck( get_attached_media(‘image’ ), ‘ID’ ) ); where we pluck out the ID’s from the get_attached_media() output. Another approach would be to use: $ids = join( ‘,’, get_attached_media( ‘_image_ids’ ) ); where we’ve introduced a new input parameter … Read more

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