Problem with multiple loops in wordpress theme

The proper way to set up a secondary query, using your example code. Instead of this: $posts = get_posts(‘numberposts=1&order=DESC&orderby=post_date&category=’.get_cat_ID( ‘سیاست’ )); Do this: // Query args $custom_cat_args = array( ‘posts_per_page’ => 1, ‘order’ => ‘DESC’, ‘orderby’ => ‘post_date’, ‘cat’ => get_cat_ID( ‘سیاست’ ) ); // Instantiate query $custom_cat_query = new WP_Query( $custom_cat_args ); // Instantiate … Read more

filter a loop base on specific category

There’s no valid query argument – category, it could be category_name or cat. So for your query, you can use – $custom_cat_args = array( ‘posts_per_page’ => 15, ‘order’ => ‘DESC’, ‘orderby’ => ‘post_date’, ‘cat’ => get_cat_ID( ‘سیاست’ ) ); Or $custom_cat_args = array( ‘posts_per_page’ => 15, ‘order’ => ‘DESC’, ‘orderby’ => ‘post_date’, ‘category_name’ => ‘سیاست’ … Read more

Style first 3 posts differently with WP_Query [duplicate]

You just need one more else statement, that’s it. <?php $lifestyle_cat = array( ‘category_name’ => ‘lifestyle’, ‘showposts’ => 3, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’ ); $lifestyle_query = new WP_Query( $lifestyle_cat ); if ( $lifestyle_query->have_posts()) { $i = 0; while ( $lifestyle_query->have_posts()) { $i++; $lifestyle_query->the_post(); if ($i==1) { // … Read more

How to correctly load a different version of main menu based on the user language in WordPress? Is it a good solution?

I had the same problem. I used Polylang plugin and 3 languages. So i created 3 menus like this: https://www.diigo.com/item/image/4o9rz/opx5. after that i checked the language and displayed the correct menu,like this: <?php if (get_locale() == ‘en_US’) { wp_nav_menu(array( ‘menu’ => ‘Primary Menu En’, ‘depth’ => 2, ‘container’ => false, ‘menu_class’ => ‘nav navbar-nav’, ‘walker’ … Read more

Add description to categories menu in admin

I am assuming this is for the built-in Category taxonomy for Posts? This would be the way of doing it. add_action( ‘registered_taxonomy’, ‘my_custom_category_paragraph’, 10, 3 ); function my_custom_category_paragraph( $taxonomy, $object_type, $args ) { global $wp_taxonomies; if ( ‘category’ !== $taxonomy ) return; // Change the callback that renders the metabox with our own. $wp_taxonomies[$taxonomy]->meta_box_cb = … Read more

Exclude subcategory from wp_query

This is pretty easy. WP_Query has different argument you can use to exclude a category. The (little) problematic part is how to exclude that category from all loops, being able to still directly querying it. You can use ‘pre_get_post’ action hook, check the ‘category_name’ argument of current query and if it’s different from ‘street-style’, exlude … Read more

Retrieve WordPress’ the_content() with jQuery

As @G.M pointed out, you need to levy the awesome AJAX API. In the example below, we fire a request to the AJAX handler, along with the parameter action=gallery_popup. $( “a” ).click( function () { $( “.gallery-pop-up-container” ).load( “/wp-admin/admin-ajax.php?action=gallery_popup” ); } ); In response to this request, WordPress will trigger an action of the same … Read more

Using php inside javascript [closed]

If you want to re-instantiate your countdown timer only after the date has been changed and saved, then, something to the effect of: //In your custom.js file…. //make sure your localized data is a dependency of your custom.js file so you have proper scope to local data jQuery(document).ready(function($){ var date, gapinvite; date = $(‘input[name=”director_date”]’); if … Read more