Articles of functions

How to debug vars inside function at functions.php file?

I have this function: function wpse_210493_apply_advertising_position( &$posts, $return = false ) { $ad_posts = array(); $content_posts = array_filter( $posts, function ( $post ) { $position = get_post_meta( $post->ID, ‘rw_adversiting_position’, true ); if ( empty( $position ) ) { return true; } $ad_posts[ intval( $position ) ] = $post; return false; } ); $content_posts = array_values( […]

How do I correct the code in php?

I am new to PHP and I’m unable to solve the code. It’s showing an error. <?php function thumbImg() { if ( has_post_thumbnail() ) { the_post_thumbnail( array(54,54) ); } else { <img src='<?php echo $data[‘featured_img’]; ?>’ alt='<?php the_title(); ?>’ /> } } ?> What I am trying to achieve is that set a fallback image […]

Using two loops in one WordPress template

Hi I am attempting to use two loops in my WP template as I am using advanced custom fields to display info from a custom post type (college) I have tested my code (label ‘loop which doesn’t work’ below) at the top of the template file and it pulls the correct data, however when I […]

Splitting the_content() by size?

I have a situation where users don’t want to format quotes in post body and want to just paste their content, assign a quote in a custom field, and the template will now render the quote when viewing their post on the website. The way I decided to do it was to add a custom […]

Using Wp_Query, Json to add Highcharts series data

I just added a custom Highchart to my wordpress single custom archive page. Using the following function call from within the Highcharts jQuery(document).ready(function(): series: [{ type: ‘column’, name : ‘<?php echo get_the_title();?>’, color:”#b6d862″, data: <?php echo average_bedroom_rental_price_for_district($post->ID, ’34’,’0′, ‘district’, $type=”DESC” );?> }] This works fine and generates the chart as expected, except for one […]

Multiple navigation menu in same location

Is it possible to have multiple menus in same location but on different pages. My pages are now: cars –car details –car specs motorbikes –motorbike dealers –map –contact Plus about 20 other pages with similar parent & child pages. Now on my site I have one place for navigation (registered as main-nav). What I would […]

Using depth=n in wp_list_pages

I’m wondering what is the proper way to use depth n in wp_list_pages. I currently have a menu in my sidebar that goes 4 levels deep but I’d like to prevent levels 3 & 4 from displaying. The codex says: ‘depth’ (int) Number of levels in the hierarchy of pages to include in the generated […]

WordPress can't get jquery/unslider to work

I don’t know what I’m doing wrong… I’m using the starter timber theme… I’m trying unslider to work with my theme… indicated here is somehow a proof I did right in putting scripts from the function.php… <script type=’text/javascript’ src=’http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/includes/js/jquery.js?ver=1′></script> <script type=’text/javascript’ src=’http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/includes/resources/bootstrap/js/bootstrap.min.js?ver=1′></script> <script type=’text/javascript’ src=’http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/includes/js/bootstrap-wp.js?ver=1′></script> <script type=’text/javascript’ src=’http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/includes/js/skip-link-focus-fix.js?ver=1′></script> <script type=’text/javascript’ src=’http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/includes/unislider/js/unslider-min.js?ver=1′></script> <script type=’text/javascript’ src=’http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/includes/js/stickyFooter.js?ver=1′></script> <script […]

How to get post category list as select in front-end?

I use widget plugin Getting the random post & URL via ajax. I want to add function, that allows users on frontend choose category, and than display random posts from this category. function get_random_post_tu() { // Simple as that, get a random post $posts = get_posts(‘orderby=rand&numberposts=1’); /** * This actually gives us an array of […]

How add body_class from wp_termmeta

I need to assign a class to the body for woocommerce categories. What I’ve done: // add the fields when the term is created add_action( ‘product_cat_add_form_fields’, ‘add_product_cat_class_field’, 10, 2 ); function add_product_cat_class_field($taxonomy) { global $feature_groups; ?><div class=”form-field term-group”> <label for=”feature-group”><?php _e(‘Custom CSS Class’, ‘my_plugin’); ?></label> <input type=”text” class=”postform” id=”custom-class” name=”custom-class” value=””> </select> </div><?php } // […]