How to get specific string in explode array?

I see two problems here. One is that the explode() doesn’t actually specify the correct split string, which is ‘, ‘, WITH a space. What is written in the sample: ‘post_type’ => explode( ‘,’, $posttype ), What is written in the example shortcode: [myquery posttype=”cpt_press, cpt_two, cpt_three, cpt_etc”] Note that there is a comma AND … Read more

Category based on post id

WP_Query itself can’t do that logic internally but you can easily create the query dynamically. $args = array( ‘meta_key’ => ‘name’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’, ‘posts_per_page’ => ‘-1’ ); if ($post->ID == 1) { $args[‘category_name’] = ‘first’; } elseif ($post->ID == 2) { $args[‘category_name’] = ‘second’; } $custom_loop = new WP_Query($args);

display post tags on single.php inside loop

You’re getting Array because that’s exactly what wp_get_post_tags returns; an array (and when you try and echo one in PHP it’ll simply output Array). As @Chip Bennet suggested, use the_tags() instead, which outputs an HTML string.

I need to exclude from a query a category and a few custom taxonomies

Change ‘relation’ => ‘OR’ to ‘relation’ => ‘AND’ to apply both exclusions to all posts returned. It may seem counterintuitive, but a post that satisfies one of the exclusions will be included even if it doesn’t satisfy the other. EDIT From the code linked in your comment below, this is the query being generated: SELECT … Read more

ACF checkbox array is returning numbers, not labels [closed]

ACF is actually doing what it should – storing a numerical array of selected values. If you want the label you can levy get_field_object, which returns information about the custom field (rather than the value of it for the given post). $field_obj = get_field_object( ‘nav_widget_platforms’ ); $platforms = get_field( ‘nav_widget_platforms’ ); foreach ( $platforms as … Read more

Get current user array into hyperlink

I would set up an array with the variables you want in the url query string and then use http_build_query(). Like so: $args = array( ‘AT’ => ‘EN’, ‘AE’ => $current_user->user_email, ‘FN’ => $current_user->user_firstname, ‘LN’ => $current_user->user_lastname, ‘MK’ => 665080128, ‘PW’ => ‘miami’, ‘BU’ => ‘http://thinkmcat.com/’); ?> <a href=”https://thinkmcat.webex.com/thinkmcat/m.php?<?php echo http_build_query($args); ?>”>LINK</a>

Get the values from an array string to work with post__in

Problem here is that, post_in accepts only array of post IDs and implode() returns string. Here’s how fixed code should look like (also added few conditional checks): $sel_ids = $_SESSION[‘selected_ids’]; /** * Check, if we have array of Post IDs */ if ( ! is_array( $sel_ids ) ) { return; } require_once(‘../../../../wp-load.php’); $args = array( … Read more

Array to modify post titles

Your example code could easily be converted to an array, like this: Updated and improved code for your new example: function manipulate_post_title( $title, $post_id ) { $title_array = array( ‘1153’ => $title . ‘-suffix’, ‘2’ => ‘prefix-‘ . $title, ‘3’ => ‘completely different title’, ); if ( is_single() && isset( $title_array[ $post_id ] ) ) … Read more

CPT while loop not working

Your post type is all wrong. Custom post type names cannot contain spaces or camelcase, also names should not contain special characters. Custom post type names, and for that matter, custom taxonomy names should be all lowercase letters, and names must only be separated by underscores (_) Have a look at the $post_type parameter in … Read more

Get latest post from categories

Ok you can use a foreach loop to return the latest post from each category. Here is how you should do that. <?php $postids = array(); $catids = array( 1, 2, 3 ); // add category ids here. foreach ( $catids as $catid ) { $my_query = new WP_Query( array( ‘cat’ => $catid, ‘ignore_sticky_posts’ => … Read more

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