alzuwaga
Forum Replies Created
-
Forum: Everything else WordPress
In reply to: Is this a bug? (date_i18n)Ah, I see. It makes sense. Thanks Otto!
Forum: Fixing WordPress
In reply to: Order post type by category and taxonomy termHi jenny, at last I can talk to someone here!
The “final work”… hmmm… is still in progress. But the idea is to make a custom query using $wpdb like this:<?php my_custom_get_terms( 'tipo', 'global', true ); $tipo = $_GET['tipo'] == '' ? '' : $_GET['tipo']; //comienzan los alojamientos no destacados GLOBAL. $datos_SQL = " SELECT wp_posts.*, wp_term_taxonomy.taxonomy, wp_terms.name AS localidad, wp_terms.slug AS localidad_slug, wp_term_taxonomy_1.taxonomy, wp_terms_1.name AS tipo FROM (((((wp_term_relationships INNER JOIN wp_term_taxonomy ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) INNER JOIN wp_terms ON wp_term_taxonomy.term_id = wp_terms.term_id) INNER JOIN wp_posts ON wp_term_relationships.object_id = wp_posts.ID) INNER JOIN wp_term_relationships AS wp_term_relationships_1 ON wp_posts.ID = wp_term_relationships_1.object_id) INNER JOIN wp_term_taxonomy AS wp_term_taxonomy_1 ON wp_term_relationships_1.term_taxonomy_id = wp_term_taxonomy_1.term_taxonomy_id) INNER JOIN wp_terms AS wp_terms_1 ON wp_term_taxonomy_1.term_id = wp_terms_1.term_id WHERE wp_term_taxonomy.taxonomy='category' AND wp_term_taxonomy_1.taxonomy='tipo' AND wp_posts.post_status='publish' AND wp_posts.post_type='alojamiento'"; if($tipo != ''){ $datos_SQL .= " AND wp_terms_1.name = '" . $tipo . "'"; } $datos_SQL .= " ORDER BY localidad, tipo"; $datos = $wpdb->get_results($datos_SQL); //var_dump($post); //print_r($wpdb->queries); if ( $datos ) : foreach ( $datos as $dato ) : // do whatever you need endforeach; else: echo "Nothing found"; endif; ?>Look at this line: $datos_SQL .= ” ORDER BY localidad, tipo”;
localidad is an alias of wp_terms.name (the category)
tipo is an alias of wp_terms_1.name (the taxonomy term)Here you have an image with the table relationships: http://i.imgur.com/V1Pj7.jpg
I hope you understand me because my inglish is not too good.
Forum: Fixing WordPress
In reply to: Order post type by category and taxonomy termWell, I just used $wpdb to run a query like the one above. Thanks anyway.
And while we’re here… why no one answers my posts? I do not ‘bumps’, I’m good and yet unanswered. I feel I can write anything, I’m like invisible here.
😀
Forum: Fixing WordPress
In reply to: Prepend category to custom post typeI did not succeed with CMS Press. but with a little research it seems that I am coming to some approximation. Using the Custom Post Type UI plugin I created:
– A custom taxonomy (CT) called ‘city’ to which I added the necessary terms (city 1, city 2, city 3)
– A Custom Post Type (CPT) called ‘accommodation’ and another called ‘gastronomy’. For ‘accommodation’ I put the rewrite rule %city%/accommodation and for ‘gastronomy’ %city%/gastronomy. Both custom post types associated with the custom taxonomy ‘city’.Then, based on this article, I placed the following code in functions.php:
add_filter('post_type_link', 'ciudad_permalink', 10, 3); function ciudad_permalink($permalink, $post_id, $leavename) { if (strpos($permalink, '%ciudad%') === FALSE) return $permalink; // Get post $post = get_post($post_id); if (!$post) return $permalink; // Get taxonomy terms $terms = wp_get_object_terms($post->ID, 'ciudad'); if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug; else $taxonomy_slug = 'sin-ciudad'; return str_replace('%ciudad%', $taxonomy_slug, $permalink); }Permalink is now http://localhost/city-name/post-type/post-name/
Great!
Any comment on that?