Use two WP Query in template

Yes, you can use two instances of WP_Query as long as you call the wp_reset_postdata function, just like you did in your code. You’re missing the while statement and posts_per_page for WP_Query array argument item. <?php $query = new WP_Query( array( ‘post_type’ => ‘item_a’, ‘posts_per_page’ => -1 /** Show all **/ ) ); if ( … Read more

PHP Customization: Taxonomies and Queries, why? [closed]

Before you start theme development, I suggest you familiarize yourself with general WordPress Usage & Terminologies. Taxonomy: In general taxonomy means classification. In WordPress, posts, pages, custom post types etc. can be further classified by using different taxonomies. For example, you may have hundreds of blog posts. Now how do you classify them for better … Read more

Select dropdown not showing selected value php

The reason your $item == $option condition is always failing is because of the way PHP compares floats! Try the following instead: echo “<option value=”$item”” . selected (abs ($item – $options) <= 0.01, true, false) . “>$item</option>” ; See Comparing floats for more info.

Restrict WordPress File Type Uploads by User Type

There is a syntax error in your conditional: current_user_can(‘administrator’) The input value is wrapped in ‘ ’, which should be wrapped in ‘ ‘ instead. Right now, because ‘administrator’ is neither a role nor capability, the above will always return a false value, therefore if(!current_user_can(‘administrator’)) will always return true, which will restrict the mime type … Read more

Is it possible to use the featured image of a page as a css background without inlining?

There’s two possible options in creating a stylesheet from a dynamically generated value. The first options is Inline stylesheet, as follows: <div id=”hero” style=”background-image: url(<?php // TODO retrieve image here. ?>); “> </div> And the second options is to use an Internal stylesheet, and possibly the best solution out of both. Using stylesheet internally requires … Read more

WordPress menu deletes when trying to add a hook

I don’t think there’s wp_nav_menu action. Perhaps you want the wp_nav_menu filter (doc)? function custom_novice_menu($args) { if( ‘primary’ == $args[‘theme_location’] ) // only apply to the right menu { $args[‘container’] = ‘div’; } return $args; } add_filter(‘wp_nav_menu’, ‘custom_novice_menu’);

Debugging PHP object during Ajax call in WordPress

If you want to see your object in that variable you have to convert it to a string: $data_str = print_r( $this, true ); Then you can include it on your error array, or if you’re just debugging your code you can send it to your web server’s error log file using error_log: error_log( $data_str … Read more

How can I export post data in xml format?

I just want to make my own exporter Well, export_wp() will fetch the data (it builds the sql query, I think). So I’m not sure the benefit of using an api request to try and hand that data to export_wp(), unless you mean to generate the arguments for it via an endpoint, or some values … Read more