diff --git a/archive-programa.php b/archive-programa.php index 57598f2e..e98794ee 100644 --- a/archive-programa.php +++ b/archive-programa.php @@ -8,20 +8,48 @@ $categoria_programa = get_query_var( 'categoria_programa' ); $arxivat = get_query_var( 'arxivat' ); -if( ! empty( $search ) || ! empty( $sistema_operatiu ) || ! empty( $categoria_programa ) || ! empty( $arxivat ) ) { +if( ! empty( $search ) || ! empty( $categoria_programa ) || ! empty( $arxivat ) ) { $query['s'] = $search; - $query['sistema-operatiu-programa'] = $sistema_operatiu; $query['categoria-programa'] = $categoria_programa; $query['arxivat'] = $arxivat; $args = get_post_query_args( 'programa', SearchQueryType::Programa, $query ); $context['cerca'] = $search; - $context['selected_filter_so'] = ( isset ( $args['filter_so'] ) ? $args['filter_so'] : '' ); $context['selected_filter_categoria'] = ( isset ( $args['filter_categoria'] ) ? $args['filter_categoria'] : '' ); $context['selected_arxivat'] = ( isset ( $args['arxivat'] ) ? $args['arxivat'] : '' ); } else { $args = get_post_query_args( 'programa', SearchQueryType::Programa ); } +if( ! empty( $sistema_operatiu ) ) { + $query['sistema-operatiu-programa'] = $sistema_operatiu; + + $args_so_baixades = array ( + 'post_type' => 'baixada', + 'tax_query' => array ( + array( + 'taxonomy' => 'sistema-operatiu-programa', + 'field' => 'slug', + 'terms' => $sistema_operatiu, + 'post_status' => 'publish' + ) + ) + ); + $baixades_posts = get_posts( $args_so_baixades ); + $programes_baixades_ids = array_map( "extract_post_ids_program", $baixades_posts ); + + if( isset( $args ) ) { + $all_programs = get_posts( $args ); + $all_programs_ids = array_map("extract_post_ids", $all_programs); + $programes_ids = array_intersect( $all_programs_ids, $programes_baixades_ids); + } else { + $programes_ids = $programes_baixades_ids; + } + $query['post__in'] = $programes_ids; + + $args = get_post_query_args( 'programa', SearchQueryType::Programa, $query ); + $context['selected_filter_so'] = $sistema_operatiu; +} + $context['content_title'] = 'Programes i aplicacions'; $post = retrieve_page_data(get_query_var( 'post_type' )); $context['categories']['sistemes_operatius'] = Timber::get_terms( 'sistema-operatiu-programa' ); diff --git a/functions.php b/functions.php index 1257c892..87f8ee4a 100755 --- a/functions.php +++ b/functions.php @@ -366,6 +366,10 @@ function get_post_query_args( $post_type, $queryType, $filter = array() ) $filter_args['s'] = $filter['s']; } + if ( ! empty ( $filter['post__in'] ) ) { + $filter_args['post__in'] = $filter['post__in']; + } + if (!empty ($filter['categoria-programa'])) { $filter_args['tax_query'][] = array( 'taxonomy' => 'categoria-programa', @@ -539,4 +543,11 @@ function sendEmailForm( $to_email, $nom_from, $assumpte, $fields ) { $output = json_encode(array('type'=>'message', 'text' => 'S\'ha enviat la informaciĆ³.')); } return $output; -} \ No newline at end of file +} + +/* Add responsive container to embeds +/* ------------------------------------ */ +function sc_embed_html( $html ) { + return '
' . $html . '
'; +} +add_filter( 'embed_oembed_html', 'sc_embed_html', 10, 3 ); \ No newline at end of file diff --git a/inc/post_types_functions.php b/inc/post_types_functions.php index 2f2bbb9f..f4288be3 100644 --- a/inc/post_types_functions.php +++ b/inc/post_types_functions.php @@ -25,4 +25,18 @@ function get_parent_page_hierarchy($parent_id, $sort_column = 'menu_order', $sor $pages_tree = str_replace( 'children', 'nav children', $pages_tree); return $pages_tree; +} + +/* + * Function that extracts the post id from a specific post (for use on array_map) + */ +function extract_post_ids( $post ) { + return $post->ID; +} + +/* + * Function that extracts the post id from a specific post relationship (for use on array_map) + */ +function extract_post_ids_program( $post ) { + return wpcf_pr_post_get_belongs( $post->ID, 'programa' ); } \ No newline at end of file diff --git a/single-programa.php b/single-programa.php index d479866f..0008abf1 100644 --- a/single-programa.php +++ b/single-programa.php @@ -25,7 +25,6 @@ $context['links'] = $post->get_field( 'link' ); $context['baixades'] = $post->get_field( 'baixada' ); $context['credits'] = $post->get_field( 'credit' ); -$context['url_video'] = wp_oembed_get( $post->video_url, array('width'=>560, 'height'=>315, 'class'=>'embed-responsive-item', 'allowfullscreen'=>1) ); if ( post_password_required( $post->ID ) ) { Timber::render( 'single-password.twig', $context ); diff --git a/templates/archive-programa.twig b/templates/archive-programa.twig index 944bde15..eb0eb8a3 100644 --- a/templates/archive-programa.twig +++ b/templates/archive-programa.twig @@ -75,7 +75,7 @@

{{ post.title }}

- + {% if post.total_baixades_programa %}({{ post.total_baixades_programa }}){% endif %}
diff --git a/templates/single-programa.twig b/templates/single-programa.twig index a452edb5..1780816c 100644 --- a/templates/single-programa.twig +++ b/templates/single-programa.twig @@ -126,18 +126,6 @@ {{ post.content }} - - {% if url_video %} -
-

{{ post.video_title }}

- -
- {{ url_video }} -
-

{{ post.video_description }}

-
- {% endif %} - {% include "comentaris.twig" %}