//Template initialization
$templates = array('plantilla-steps.twig');
//Project
$project_slug = get_query_var('project');
if (!empty($project_slug)) {
    $projecte = get_page_by_path($project_slug, OBJECT, 'projecte');
    $projecte = new TimberPost($projecte->ID);
    $content_title = 'Col·laboreu en el projecte ' . $projecte->post_title;
    $projecte->project_requirements = apply_filters('the_content', $projecte->project_requirements);
    $projecte->lectures_recomanades = apply_filters('the_content', $projecte->lectures_recomanades);
    $context_filterer = new SC_ContextFilterer();
    $context = $context_filterer->get_filtered_context(array('title' => $content_title . '| Softcatalà'));
    $context['projecte'] = $projecte;
    $context['steps'] = $projecte->get_field('steps');
    $templates = array('plantilla-steps-single.twig');
    $args = array('meta_query' => array(get_meta_query_value('projectes', $projecte->ID, 'like', '')));
    $context['membres'] = get_users($args);
} else {
    $post = Timber::get_post();
    $profile = $post->get_field('perfil');
    $profile_label = get_field_object('perfil', $post->ID);
    $all_acf_data = get_field_objects($post->ID);
    $content_title = 'Col·laboreu amb nosaltres: ' . $profile_label['choices'][$profile];
    if (false === $profile || empty($profile)) {
        wp_redirect('/col·laboreu/', 302);
    }
    $project_args = array('tax_query' => array(array('taxonomy' => 'ajuda-projecte', 'field' => 'slug', 'terms' => $profile), array('taxonomy' => 'classificacio', 'field' => 'slug', 'terms' => 'arxivat', 'operator' => 'NOT IN')));
    $projects = $sc_types['projectes']->get_sorted_projects($project_args);
    $context = Timber::get_context();
    $context['projectes'] = $projects;
    $context['steps'] = $post->get_field('steps');
Example #2
0
function get_post_query_args($post_type, $queryType, $filter = array())
{
    //Retrieve posts
    switch ($post_type) {
        case 'esdeveniment':
            $base_args = array('meta_key' => 'wpcf-data_inici', 'post_type' => $post_type, 'post_status' => 'publish', 'orderby' => 'wpcf-data_inici', 'order' => 'ASC', 'paged' => get_is_paged(), 'posts_per_page' => 10);
            break;
        case 'aparell':
            $base_args = array('post_type' => $post_type, 'post_status' => 'publish', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => -1);
            break;
        case 'programa':
            $base_args = array('post_type' => $post_type, 'post_status' => 'publish', 'orderby' => 'title', 'order' => 'ASC', 'paged' => get_is_paged(), 'posts_per_page' => 18, 'tax_query' => array(array('taxonomy' => 'classificacio', 'field' => 'slug', 'terms' => 'arxivat', 'operator' => 'NOT IN')));
            break;
        case 'projecte':
            $base_args = array('post_type' => $post_type, 'post_status' => 'publish', 'orderby' => 'title', 'order' => 'ASC', 'paged' => get_is_paged(), 'posts_per_page' => 36, 'tax_query' => array(array('taxonomy' => 'classificacio', 'field' => 'slug', 'terms' => 'arxivat', 'operator' => 'NOT IN')));
            break;
        case 'page':
            $base_args = array('post_type' => $post_type, 'post_status' => 'publish', 'order' => 'ASC', 'meta_query' => array(get_meta_query_value('wpcf-' . $filter['subpage_type'], $filter['post_id'], '=', 'NUMERIC')));
            break;
        case 'post':
            $base_args = array('post_type' => $post_type, 'post_status' => 'publish', 'order' => 'DESC', 'paged' => get_is_paged(), 'posts_per_page' => 10);
            break;
    }
    $filter_args = array();
    if ($queryType == SearchQueryType::Post) {
        if (!empty($filter['s'])) {
            $filter_args['s'] = $filter['s'];
        }
        if (!empty($filter['categoria'])) {
            $filter_args['category__and'] = $filter['categoria'];
        }
    } else {
        if ($queryType == SearchQueryType::Search) {
            $filter_args = array('s' => $filter, 'meta_query' => array(get_meta_query_value('wpcf-data_fi', time(), '>=', 'NUMERIC')));
        } else {
            if ($queryType == SearchQueryType::FilteredDate) {
                $filter_args = array('meta_query' => array('relation' => 'AND', array(get_meta_query_value('wpcf-data_fi', $filter['start_time'], '>=', 'NUMERIC')), array(get_meta_query_value('wpcf-data_inici', $filter['final_time'], '<=', 'NUMERIC'))));
            } else {
                if ($queryType == SearchQueryType::Highlight) {
                    $filter_args = array('posts_per_page' => 2, 'meta_key' => 'wpcf-destacat', 'orderby' => 'meta_value', 'order' => 'DESC', 'meta_query' => array(get_meta_query_value('wpcf-destacat', '0', '>=', 'NUMERIC'), get_meta_query_value('wpcf-data_inici', '0', '>=', 'NUMERIC'), get_meta_query_value('wpcf-data_fi', time(), '>=', 'NUMERIC')));
                } else {
                    if ($queryType == SearchQueryType::Aparell) {
                        $filter_args = array();
                        if (!empty($filter['s'])) {
                            $filter_args['s'] = $filter['s'];
                        }
                        if (!empty($filter['so_aparell'])) {
                            $filter_args['tax_query'][] = array('taxonomy' => 'so_aparell', 'field' => 'slug', 'terms' => $filter['so_aparell']);
                            $filter_args['filter_so'] = $filter['so_aparell'];
                        }
                        if (!empty($filter['tipus_aparell'])) {
                            $filter_args['tax_query'][] = array('taxonomy' => 'tipus_aparell', 'field' => 'slug', 'terms' => $filter['tipus_aparell']);
                            $filter_args['filter_tipus'] = $filter['tipus_aparell'];
                        }
                        if (!empty($filter['fabricant'])) {
                            $filter_args['tax_query'][] = array('taxonomy' => 'fabricant', 'field' => 'slug', 'terms' => $filter['fabricant']);
                            $filter_args['filter_fabricant'] = $filter['fabricant'];
                        }
                    } else {
                        if ($queryType == SearchQueryType::Programa) {
                            $filter_args = array();
                            //Avoid posts arxivats
                            $filter_args['tax_query'][] = array('taxonomy' => 'classificacio', 'field' => 'slug', 'terms' => 'arxivat', 'operator' => 'NOT IN');
                            if (!empty($filter['s'])) {
                                $filter_args['s'] = $filter['s'];
                            }
                            if (!empty($filter['sistema-operatiu-programa'])) {
                                $filter_args['tax_query'][] = array('taxonomy' => 'sistema-operatiu-programa', 'field' => 'slug', 'terms' => array($filter['sistema-operatiu-programa'], 'multiplataforma'));
                                $filter_args['filter_sistema_operatiu'] = $filter['sistema-operatiu-programa'];
                            }
                            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', 'field' => 'slug', 'terms' => $filter['categoria-programa']);
                                $filter_args['filter_categoria'] = $filter['categoria-programa'];
                            }
                        } else {
                            if ($queryType == SearchQueryType::PagePrograma || $queryType == SearchQueryType::Projecte) {
                                $filter_args = array();
                            } else {
                                if ($queryType == SearchQueryType::FilteredTema) {
                                    if (!empty($filter)) {
                                        $filter_args['tax_query'][] = array('taxonomy' => 'esdeveniment_cat', 'field' => 'slug', 'terms' => $filter);
                                    }
                                } else {
                                    $filter_args = array('meta_query' => array(get_meta_query_value('wpcf-data_fi', time(), '>=', 'NUMERIC')));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return array_merge($base_args, $filter_args);
}
Example #3
0
    $author = new TimberUser($wp_query->query_vars['author']);
    $context_holder['author'] = $author;
    $context_holder['author_role'] = get_user_role($author);
    $context_holder['author_content'] = apply_filters('the_content', $author->{'wpcf-descripcio_activitat'});
    $context_holder['author_image'] = get_gravatar_url($author->user_email);
    $context_holder['content_title'] = 'Publicades per ' . $author->name();
    $title = $author->name() . ' - Softcatalà';
    $description = $author->description();
    $projectes_ids = get_user_meta($author->ID, 'projectes', true);
    if ($projectes_ids) {
        $context_holder['projectes'] = array_map(function ($projecte_id) {
            $_projecte = get_post($projecte_id);
            return array('link' => get_post_permalink($projecte_id), 'title' => $_projecte->post_title);
        }, $projectes_ids);
    }
} else {
    $template = array('archive-author.twig');
    $post = new TimberPost();
    $context_holder['post'] = $post;
    //Show only active members
    $args = array('meta_query' => array(get_meta_query_value('wpcf-status_membre', 0, '>', '')));
    $authors = get_users($args);
    $context_holder['authors'] = $authors;
    $context_holder['content_title'] = 'Membres de Softcatalà';
    $context_holder['sidebar_elements'] = array('static/suggeriment.twig', 'baixades.twig', 'links.twig');
}
//Context initialization
$context_filterer = new SC_ContextFilterer($context_holder);
$context_overrides = array('title' => $title, 'description' => $description);
$context = $context_filterer->get_filtered_context($context_overrides, false);
Timber::render($template, $context);