Visualizzazione dei risultati da 1 a 10 su 10

Hybrid View

  1. #1
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560

    query array doppio valore

    Ciao, dovrei inserire anche il valore '1' oltre allo '0' in value...come fare? grazie

    Codice PHP:
    'meta_query' => array( array('key' => 'premium''value' => '0''compare' => '=''type' => 'NUMERIC') ), 

  2. #2
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,445
    Non puoi avere 2 chiavi con lo stesso nome, devi trovare un sistema diverso per memorizzare il dato.

  3. #3
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    Grazie, questo è il codice:

    Codice PHP:
                    <?php
                    $args 
    = array(
                        
    'post_type' => $taxonomy_profile_url,
                        
    'meta_query' => array( array('key' => 'premium''value' => '0''compare' => '=''type' => 'NUMERIC') ),
                        
    'posts_per_page' => get_option("frontpageshownormalcols") * 5
                    
    );
                    
    $normal_profiles = new WP_Query$args );
                    
    $i "1";
                    if (
    $normal_profiles->have_posts()) :
                        while ( 
    $normal_profiles->have_posts() ) : $normal_profiles->the_post();
                            include (
    get_template_directory() . '/loop-show-profile.php');
                        endwhile;
                    else:
                        
    _de('No %s here yet',29,$taxonomy_profile_name_plural);
                    endif;
                    
    wp_reset_postdata();
                    
    ?>



    Ho provato così ma nulla:

    Codice PHP:
                    <?php
                    $args 
    = array(
                        
    'post_type' => $taxonomy_profile_url,
                        
    'meta_query' => array( array('key' => 'premium''value' => '0''compare' => '=''type' => 'NUMERIC') ),
                        
    'posts_per_page' => get_option("frontpageshownormalcols") * 5
                    
    ); 
                    
    $premium_args = array(
                        
    'post_type' => $taxonomy_profile_url,
                        
    'meta_query' => array( array('key' => 'premium''value' => '1''compare' => '=''type' => 'NUMERIC') ),
                        
    'posts_per_page' => get_option("frontpageshownormalcols") * 5
                    
    );
                    
    $normal_profiles = new WP_Query$args );                $normal_profiles = new WP_Query$premium_args );
                    
    $i "1";
                    if (
    $normal_profiles->have_posts()) :
                        while ( 
    $normal_profiles->have_posts() ) : $normal_profiles->the_post();
                            include (
    get_template_directory() . '/loop-show-profile.php');
                        endwhile;
                    else:
                        
    _de('No %s here yet',29,$taxonomy_profile_name_plural);
                    endif;
                    
    wp_reset_postdata();
                    
    ?>


    Cosa sbaglio?
    Ultima modifica di Lino80; 21-12-2019 a 11:11

  4. #4
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,445
    Da quel codice lì capisco che stai modificando o scrivendo un qualche plugin per WordPress per prendere dei post, ma poi chiedi solo "cosa sbaglio?".
    Dovresti anche dire cosa vorresti che facesse e invece cosa ottieni.

  5. #5
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    Si tema wordpress.

    'value' => '0' mi stampa i valori dove premium è = a 0
    'value' => '1' mi stampa quelli dove è = a 1


    vorrei che mi stampasse entrambi i valori di 'premium' = 0 e 1

  6. #6
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    Ho provato così ma nulla:

    Codice PHP:
                    $args = array(
                        
    'post_type' => $taxonomy_profile_url,
                        
    'meta_query' => array( array('key' => 'premium''value' => '0''compare' => '=''type' => 'NUMERIC') ),
                        
    'posts_per_page' => get_option("frontpageshownormalcols") * 5
                    
    );                                $args2 = array(

                        
    'meta_query' => array( array('key' => 'premium''value' => '1''compare' => '=''type' => 'NUMERIC') ),

                    );
                    
    $normal_profiles = new WP_Query($args$args2); 
    vado a tentativi non essendo programmatore

  7. #7
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    così dovrebbe funzionare ma mi restituisce i post del blog e non gli utenti



    Codice PHP:
                    <?php
                    $args 
    = array(
                        
    'post_type' => $taxonomy_profile_url,                                        
                        
    'post__in' => $r,
                        
    'meta_query' => array( array('key' => 'premium''value' => '0''compare' => '=''type' => 'NUMERIC') ),
                        
    'posts_per_page' => get_option("frontpageshownormalcols") * 5
                    
    );      
                    
    $args2 = array(
                        
    'post_type' => $taxonomy_profile_url,                                        
                        
    'post__in' => $r,
                        
    'meta_query' => array( array('key' => 'premium''value' => '1''compare' => '=''type' => 'NUMERIC') ),
                        
    'posts_per_page' => get_option("frontpageshownormalcols") * 5
                    
    );                                
    $ids array_merge($args->posts$args2->posts);                
    $normal_profiles = new WP_Query(array('post__in' => $ids,'orderby' => 'post__in'));
                    
    $i "1";
                    if (
    $normal_profiles->have_posts()) :
                        while ( 
    $normal_profiles->have_posts() ) : $normal_profiles->the_post();
                            include (
    get_template_directory() . '/loop-show-profile.php');
                        endwhile;
                    else:
                        
    _de('No %s here yet',29,$taxonomy_profile_name_plural);
                    endif;
                    
    wp_reset_postdata();
                    
    ?>

  8. #8
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    Codice PHP:
                    <?php
                    $args 
    = array(
                        
    'post_type' => $taxonomy_profile_url,                                        'post__in' => $r,
                        
    'meta_query' => array( array('key' => 'premium''value' => '0''compare' => '=''type' => 'NUMERIC') ),
                        
    'posts_per_page' => get_option("frontpageshownormalcols") * 5
                    
    );                $premium = new WP_Query$args );                $premium_found_posts $premium->found_posts;                                $args2 = array(
                        
    'post_type' => $taxonomy_profile_url,                                        'post__in' => $r,
                        
    'meta_query' => array( array('key' => 'premium''value' => '1''compare' => '=''type' => 'NUMERIC') ),
                        
    'posts_per_page' => get_option("frontpageshownormalcols") * 5
                    
    );                                $normal = new WP_Query$args2 );                $premium_found_posts $normal->found_posts;                                $all $premium;

                            
    $q array_merge($premium->posts$normal->posts);
                            
    $all->posts $q;

                    
    $i "1";
                        if ( 
    $all->have_posts() ) : while ( $all->have_posts() ) : $all->the_post();
                            include (
    get_template_directory() . '/loop-show-profile.php');
                        endwhile;
                    else:
                        
    _de('No %s here yet',29,$taxonomy_profile_name_plural);
                    endif;
                    
    wp_reset_postdata();
                    
    ?>

    così credo che vada bene.......ma........mi da errore: mod_fcgid: stderr: PHP Warning: array_unique() expects parameter 1 to be array, null given in /web/htdocs1/dom/home/www/wp-includes/post-template.php on line 834

  9. #9
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    riga 834:
    Codice PHP:
    function wp_link_pages$args '' ) {    
    global 
    $page$numpages$multipage$more

  10. #10
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    Risolto con sistema diverso come dicevi tu Alhazred
    Semplicemente inserendo 'key' => 'altrovalore', buone feste

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.