Custom content before post content

You can check the post type of the current post via get_post_type: function theme_slug_filter_the_content( $content ) { if( ‘post’ == get_post_type() ){ $custom_content=”YOUR CONTENT GOES HERE”; return $custom_content . $content; } return $content; } add_filter( ‘the_content’, ‘theme_slug_filter_the_content’ );

Display specific posts on home page

You have to know the ID/s of the category/categories you wish to show. Then add ‘category’ => ‘X’ in the array. X is the ID of your category. Example: $args = array( ‘numberposts’ => ‘5’, ‘category’ => ‘3’ ); or if you wish more then one category: $args = array( ‘numberposts’ => ‘5’, ‘category’ => … Read more

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.

The loop does not show users

You need to add this code to the file functions.php. function custom_post_author_archive($query) { if ($query->is_author) $query->set( ‘post_type’, array(‘post-type’, ‘post’) ); remove_action( ‘pre_get_posts’, ‘custom_post_author_archive’ ); } add_action(‘pre_get_posts’, ‘custom_post_author_archive’);

Echo array value

If you just need to have the print_array($var) provide an array of values, then you need to change the database function from $wpdb->get_results to $wpdb->get_var. You are retrieving just one value from the database, so get_var is the function which will return that specific value directly. Edit: You can create a comma separated list from … Read more

Search Results Page – Displaying Custom Meta Fields

You’ve got a missing ) and you’re passing true as a string and not a boolean value. So this line: $pName = get_post_meta($post->ID, $productName, ‘true’; Should in fact be: $pName = get_post_meta($post->ID, $productName, true); In light of your update why not do something like: echo ‘Product Name: ‘. $pName[‘productName’][0]; echo ‘Location: ‘. $pName[‘locationName’][0]; echo ‘Address: … Read more

Exclude category from get_the_category

$cat_ids = wp_list_pluck( $cat, ‘term_id’ ); Once you get the category ids as you have mentioned above, you can search for the key having the category id 68 as $key = array_search(’68’, $cat_ids); Once you get the key, you can unset/remove that from the array as unset($cat_ids[$key]); Once that is removed, you can use the … Read more

Optimize CPT-function with a loop

Finally I got the solution. One of the major problems was the usage of “get_post_custom” for fetching the database. I used “get_post_meta” instead and it was a lot easier to work with the array that was created by that function. I am sure that it would have been possible to do it with the first … Read more

Display all images from specific CPT

You are on the right track here, but it is a bit bumpy Firstly, caller_get_posts is depreciated, that has been replaced with ignore_sticky_posts Secondly, you should use wp_reset_postdata not wp_reset_query. The latter is used in conjuction with query_posts which should never be used. Thirdly, your call to images should be inside your loop, not outside. … Read more