Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente bannato
    Registrato dal
    Jun 2003
    Messaggi
    1,011

    piccola modifica a questa funzione!! Help me

    Praticamente grazie alla funzione qui in basso wordpress cerca i post correlati a quello principale in base alle keyword associate al post, e in concomitanza di anche una sola keyword lui ti associa i post. Voi adesso vi chiederete cosa voglio io io vorrei che solamente quando combaciano 2 keywords lui mi associa i posts, solo che non masticando php non saprei dove mettere le mani


    Codice PHP:
    function GetRelatedPosts($tags$limit 0) {
            global 
    $wpdb$tabletags$tablepost2tag$post$typelimitsql;

            
    $now current_time('mysql'1);

            
    $taglist "'" str_replace("'",'',str_replace('"','',urldecode($tags[0]->tag))). "'";
            
    $tagcount count($tags);
            if (
    $tagcount 1) {
                for (
    $i 1$i <= $tagcount$i++) {
                    
    $taglist $taglist ", '" str_replace("'",'',str_replace('"','',urldecode($tags[$i]->tag))) . "'";
                }
            }

            if (
    $post->ID) {
                
    $notclause "AND p.ID != $post->ID";
            }

            if (
    $limit != 0) {
                
    $limitclause "LIMIT $limit";
            }

            
    $q = <<<SQL
            SELECT DISTINCT p.*, count(p2t.post_id) as cnt
                 FROM 
    $tablepost2tag p2t, $tabletags t, $wpdb->posts p
                 WHERE p2t.tag_id = t.tag_id
                 AND p2t.post_id = p.ID
                 AND (t.tag IN (
    $taglist))
                 AND post_date_gmt < '
    $now'
                 AND 
    $typelimitsql
                 
    $notclause
                 GROUP BY p2t.post_id
                 ORDER BY cnt DESC, post_date_gmt DESC
                 
    $limitclause
    SQL;

            return 
    $wpdb->get_results($q);
        } 

  2. #2
    prova ad aggiungere la clausola HAVING...

    codice:
            $q = <<<SQL
            SELECT DISTINCT p.*, count(p2t.post_id) as cnt
                 FROM $tablepost2tag p2t, $tabletags t, $wpdb->posts p
                 WHERE p2t.tag_id = t.tag_id
                 AND p2t.post_id = p.ID
                 AND (t.tag IN ($taglist))
                 AND post_date_gmt < '$now'
                 AND $typelimitsql
                 $notclause
                 GROUP BY p2t.post_id
                 HAVING cnt > 1
                 ORDER BY cnt DESC, post_date_gmt DESC
                 $limitclause
    SQL;
    occhio a modificare la sintassi heredoc... a non lasciare spazi in fondo dopo SQL;

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

  3. #3
    Utente bannato
    Registrato dal
    Jun 2003
    Messaggi
    1,011
    Grazie!! Funziona!!

    Secondo te una funzione del genere non succhia troppe risorse al sistema ?

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 © 2025 vBulletin Solutions, Inc. All rights reserved.