Create shortcode for list of custom post titles with custom fields alongside

Try the following code: (I’ve not tested it, so there might be few things here and there, but you can get the overall idea): add_shortcode(‘boats’, ‘shortcode_boats’); function shortcode_boats($atts){ //merge the passed attributes with defaults extract( shortcode_atts( array( ‘post_type’ => ‘yacht-for-sale’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => 15, ‘caller_get_posts’ => 1 //i am not sure what you … Read more

Display only posts with comments

Since you are in a loop you can use the function get_comments_number(). Retrieves the value of the total number of comments, Trackbacks, and Pingbacks for a post. This tag must be within The Loop. Unlike comments_number() this function will return the value as a numeric value. Use it for example as follows: $num_comments = get_comments_number(); … Read more

shortcode for recent custom type post

This seems to work with custom post type : function get_custom_posts( $params ) { extract( shortcode_atts( array ( ‘number’ => ‘1’, ‘excerpt’ => 290, ‘readmore’ => ‘no’, ‘cpt’ => ‘post’, ‘readmoretext’ => ‘Read more’ ), $params ) ); //$latest_posts = get_posts( ‘category=0&numberposts=” . $number . “&suppress_filters=false’); OLD $latest_posts = query_posts( ‘post_type=”.$cpt.”&posts_per_page=” . $number ); wp_reset_query(); … Read more

Custom shortcode that writes to file

Your code works for me on a development server. As is, it saves to the site root directory. My guess is that you are trying to write to a directory to which the server does not have write access. I would suggest saving to wp-content/uploads or some other directory where you should reasonably have write … Read more

div having different appearances in different themes

You need to be specific when defining your CSS styles so that a theme will not overwrite your intended style. When outputting your markup, perhaps you should even consider wrapping your div element within another div element and assuming this is the only markup on the page, you can specify them both with an #ID … Read more

Custom field in a shortcode?

$post is global variable, so it’s not visible in this scope (and when you use $post in your code, you’re not referring to global $post variable but to local one) You should put global $post somewhere in your code. For example like this: … while ($loop->have_posts()){ global $post; $loop->the_post(); $output .= ‘<li><a href=”‘.get_permalink().'”><img src=”‘.get_post_meta($post->ID,’wpcf-udstiller-logo’,true).'”/></a></li>’; } … Read more

Custom field within shortcode

If you want to put the custom fields inside the shortcode…you actually should put the custom fields inside the shortcode. Be sure that your fields content does not get echoed, according to ACFs resources you have to use get_field($field_name) within the loop. Try: <?php echo print_wp_cart_button_for_product(get_field(‘product_name’), get_field(‘product_price’)); ?>

Add number in increment of one to DIV ID

the code should be instead add_shortcode( ‘faq’, ‘wpse105856_shortcode_callback’ ); function wpse105856_shortcode_callback( $atts ) { extract( shortcode_atts( array( ‘category’ => ” ), $atts ) ); $args = array( ‘numberposts’ => -1, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ‘post_type’ => ‘faq’ ); if ( ! empty( $category ) ) { $args[‘category_name’] = $category; }; $posts = get_posts( … Read more