Custom query question, and a big thank you
-
First of all, THANK YOU SO MUCH for this plugin. Even though I have not used it on a live site yet, but I have been tinkering with it for the past several days and going over your documentation (PDF and online), and all plugin related support tickets (all 24 pages of them hehehe). Polylang seems solid and a true performer to say the least, but above all, your continuous and prompt support that I have personally felt in all the support threads are immense and should be applauded. So thank you!
Before I start I must indicate that I am a designer and not a hardcore developer, and thus some of the terms you used in your documentation eluded me. I have:
Languages
-
Arabic (default)
English
All categories have been translated.In my home.php file, I have several custom queries that present articles in blocks from various categories. Here is a sample code block:
function halkibsi_multimedia_multicolumn_loop() { global $post; $formats = get_post_format_slugs(); foreach ( (array) $formats as $i => $format ) { $formats[$i] = 'post-format-' . $format; } $multimedia_posts = get_posts( array( 'post_type' => 'post', 'category' => 21, // Arabic Category ID 'lang' => 'ar', // use language slug in the query 'posts_per_page' => 4, 'offset' => 0, 'orderby' => 'post_date', 'post_status' => 'publish', 'tax_query' => array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => $formats, ), ) ) ); // $counter = 0; foreach( $multimedia_posts as $post ) : setup_postdata($post); if($counter % 2 == 0) : // half of the the showposts count in the query echo '<div style="display: table-row;">'; endif; // LOOP HTML OUTPUT CODE HERE $counter++; if($counter % 2 == 0) : // half of the the showposts count in the query echo '</div>'; endif; endforeach; wp_reset_postdata(); wp_reset_query(); }
Additional Information:
-
Category “21” (in the query) is the Arabic category
Category “37” (not in query) is the English translationQuestion:
How do I re-write this function so that Polylang will automatically identify the current language and return values from the translated category, in this case “37”? Or I’m sure your have a better function than mine. I welcome any suggestions ??Thanks again!
—–
1. your permalinks settings
custom permalinks –> /%category%/%post_id%/%postname%/
—–
2. if you are using a static front page
Yes, but NOT through the admin Settings > Reading option, but by naming my file as home.php
—–
3. your Polylang settings
screenshot –> https://dl.dropboxusercontent.com/u/6411826/screenshot.png
- The topic ‘Custom query question, and a big thank you’ is closed to new replies.