Problems with explode [closed]

It’s because you’ve created an array with explode and assigned it to $string, then you’re appending strings onto it when you use the .= concatenation operator within your foreach loop. here’s a simpler method: $string = ‘-‘ . implode( ‘,-‘, explode( ‘ ‘, $data[‘exclude_categories’] ) );

trouble with my loop

cat accepts category IDs, not slugs or names. a better method here is to use the pre_get_posts action, the Codex page has an example that does exactly what you’re trying to do.

Exclude Author by ID

Where $that_user_your_filtering_out is the user/author ID you wan’t to filter out, make this modification to your loop foreach ($blogusers as $bloguser) { // modification starts here if($bloguser->user_id == $that_user_your_filtering_out){ continue; } // modification ends here echo ‘<div class=”content-slider-body”>’; $user = get_userdata($bloguser->user_id);

Display 1 category only with get_the_category (by ID or slug)

I think you could do something like this: $categories = get_the_category(); $displayed_category_id = 1; // set this to the category ID you want to show $output=””; if($categories){ foreach($categories as $category) { if ( $displayed_category_id == $category->term_id) { $output .= ‘<a href=”‘.get_category_link($category->term_id ).'” title=”‘ . esc_attr( sprintf( __( “View all posts in %s” ), $category->name ) … Read more

How to display elements of different post types?

I am not sure I understand your conditions but I think you want something like this: $arg = array ( ‘post_type’ => array(‘post’,’placas’), ‘orderby’ => ‘rand’, ‘tax_query’ => array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘firmas’, ‘field’ => ‘slug’, ‘terms’ => array( ‘LG’ ), ‘operator’ => ‘NOT IN’, ), array( ‘taxonomy’ => ‘category’, ‘field’ => … Read more

Category menu that filters out empty categories

I had an error in the above code. $key used in both for loops. Working code for filtering empty product categories out of menu items: function exclude_empty_cat_menu_items( $items, $menu, $args ) { // Get a list of product categories that excludes empty categories $non_empty_categories = get_categories(array(‘taxonomy’ => ‘product_cat’)); // Iterate over the menu items foreach … Read more

widget exclude post by custom field

The meta_query parameter in WP_Query allows you to query posts that don’t have a certain custom field. Furthermore, you can check for multiple custom fields. With two queries in meta_query, you can fetch all posts that either don’t have a custom field, or have it set to 0: ‘meta_query’ => array( ‘relation’ => ‘OR’, array( … Read more