Salta al contenuto
  • CATEGORIES
  • La Community Connect.gt
  • Presentati alla Community
  • News Ufficiali da Connect.gt
  • Internet News
  • A Scuola Di
  • Digital Marketing
  • Intelligenza Artificiale
  • SEO & GEO
  • Web Marketing e Content
  • Google Analytics e Web Analytics
  • Google Ads & Advertising
  • YouTube
  • TikTok, Instagram e altri Social
  • Google Adsense, Affiliazioni e Guadagno
  • E-Commerce
  • Coding e Sistemistica
  • Help Center: consigli per il tuo progetto
  • Hosting e Cloud
  • Coding
  • CMS & Piattaforme Self-Hosted
  • Annunci e Collaborazioni
  • Annunci Vendita e Acquisto: Pubblicità, Domini, Link e altro
  • Collaborazioni WEB e Lavoro: offro e cerco
  • Impresa, Fisco e Leggi
  • Consulenza Legale e Professioni Web
  • Consulenza Fiscale, Imprese, Startup e P.Iva
  • Gli Off Topic
  • PC, Smartphone e altri Hardware
  • Tutti i Software
  • GT Fetish Cafè
  • Discussioni
  • 0 Non letti 0
  • Recenti
  • Hashtag
  • Popolare
  • Utenti
  • Privacy
  • Termini e condizioni
  • © 2026 Search On Media Group S.r.l.
Collassa
Connect.gt
Il network Search On
Connect.gt WMF AI Festival Accademia Advanced SEO Tool AgentCy Social Media Strategies Search Tech
Registrati Accedi
Connect.gt
Stream Interest Categorie Hashtag
P

pagineverdi

@pagineverdi
Non seguire Segui
Informazioni
Post
2
Discussioni
1
Condivisioni
0
Gruppi
0
Da chi è seguito
0
Chi segue
0

Post

Recenti Migliore Controverso

  • Da MYSQL a WORDPRESS
    P pagineverdi
    CMS & Piattaforme Self-Hosted

    Intanto Grazie per l'intervento, avevo già visto quanto da te linkato, e sono veramente vicino alla soluzione infatti questa è la query a cui sono arrivato

    SELECT 
        wp_posts.* 
    FROM 
    wp_posts 
    INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) 
    LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) 
    LEFT JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id AND mt1.meta_key = 'dir_featured' ) 
    WHERE 1=1 AND 
    ( wp_term_relationships.term_taxonomy_id IN (2159) ) AND 
    ( ( wp_postmeta.meta_key = 'dir_featured' AND CAST(wp_postmeta.meta_value AS CHAR) = 'yes' ) OR mt1.post_id IS NULL ) AND wp_posts.post_type = 'ait-dir-item' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID 
    ORDER BY 
    wp_postmeta.meta_value DESC, 
    wp_posts.post_date DESC
    

    mentre devo arrivare a questa

    SELECT
    [B]    IF(wp_postmeta.meta_value = 'yes',post_date,'zz') as mv,[/B]
        wp_posts.*
    FROM wp_posts
    INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
    LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
    LEFT JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id AND mt1.meta_key = 'dir_featured' )
    WHERE
    ( wp_term_relationships.term_taxonomy_id IN (".$queried_object ->term_id.") ) AND
    ( ( wp_postmeta.meta_key = 'dir_featured' AND CAST(wp_postmeta.meta_value AS CHAR) = 'yes' ) OR mt1.post_id IS NULL ) AND
    wp_posts.post_type = 'ait-dir-item' AND
    wp_posts.post_status = 'publish'
    GROUP BY
    wp_posts.ID
    ORDER BY
    [B]mv ASC,[/B]
    wp_posts.post_date DESC
    

    in grassetto ho messo cosa cambia fra le 2.

    avevo percorso la strada di utilizzare direttamente la query sul codice, ma mi serve il risultato come lo restituisce ik WP_Query visto il codice già esistente, andarlo a stravolgere non sarebbe proprio il caso.

    quì i parametri utilizzati fino ad ora

        $params = array(
            'post_type'            => 'ait-dir-item',
            'nopaging'            =>    true,
            'meta_query' => array(
                'relation' => 'OR',
                    array(
                        'key' => 'dir_featured',
                        'value' => 'yes',
                        'compare' => '='
                    ), 
                    array(
                        'key' => 'dir_featured',
                        'value' => '',
                        'compare' => 'NOT EXISTS'
                    )
                )    ,
            'orderby'             => array( 'dir_featured' => 'DESC','post_date' => 'DESC'  ),
            'post_status'        => 'publish',
            'tag__in'            => $queried_object ->term_id
        );
    

    Grazie ancora attendo info 🙂


  • Da MYSQL a WORDPRESS
    P pagineverdi
    CMS & Piattaforme Self-Hosted

    Salve a tutti,
    stò modificando delle funzioni di un tema premium acquistato di themeforest e stò avendo qualche problema con una query.

    Io ho questo codice:

    function getItemTag($tag) {
    
    $queried_object = get_queried_object();
    
    $params = array(
    'post_type'    => 'ait-dir-item',
    'nopaging'    =>    true,
    'meta_query' => array(
    'relation' => 'OR',
    array(
    'key' => 'dir_featured',
    'value' => 'yes',
    'compare' => '='
    ),
    array(
    'key' => 'dir_featured',
    'value' => '',
    'compare' => 'NOT EXISTS'
    )
    )    ,
    'orderby' => array( 'dir_featured' => 'DESC','post_date' => 'DESC'  ),
    'post_status'    => 'publish',
    'tag__in'    => $queried_object ->term_id
    );
    
    $itemsQuery = new WP_Query();
    $items = $itemsQuery->query($params);
    
    foreach ($items as $key => $item) {
    // options
    $item->optionsDir = get_post_meta($item->ID, '_ait-dir-item', true);
    
    // link
    $item->link = get_permalink($item->ID);
    // thumbnail
    $image = wp_get_attachment_image_src( get_post_thumbnail_id($item->ID), 'full' );
    if($image !== false){
    $item->thumbnailDir = $image[0];
    } else {
    $item->thumbnailDir = $GLOBALS['aitThemeOptions']->directory->defaultItemImage;
    }
    // marker
    $terms = wp_get_post_terms($item->ID, 'ait-dir-item-category');
    $termMarker = $GLOBALS['aitThemeOptions']->directoryMap->defaultMapMarkerImage;
    if(isset($terms[0])){
    $termMarker = getCategoryMeta("marker", intval($terms[0]->term_id));
    }
    $item->marker = $termMarker;
    // excerpt
    $item->excerptDir = aitGetPostExcerpt($item->post_excerpt,$item->post_content);
    // package class
    $item->packageClass = getItemPackageClass($item->post_author);
    // rating
    $item->rating = get_post_meta( $item->ID, 'rating', true );
    
    }
    
    return $items;
    
    }
    

    che mi da dei risultati in ordine sbagliato rispetto a come li vorrei. Ho trovato in Mysql la soluzione con la seguente query

    SELECT
    IF(wp_postmeta.meta_value = 'yes',post_date,'zz') as mv,
    wp_posts.*
    FROM wp_posts
    INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
    LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
    LEFT JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id AND mt1.meta_key = 'dir_featured' )
    WHERE
    ( wp_term_relationships.term_taxonomy_id IN (".$queried_object ->term_id.") ) AND
    ( ( wp_postmeta.meta_key = 'dir_featured' AND CAST(wp_postmeta.meta_value AS CHAR) = 'yes' ) OR mt1.post_id IS NULL ) AND
    wp_posts.post_type = 'ait-dir-item' AND
    wp_posts.post_status = 'publish'
    GROUP BY
    wp_posts.ID
    ORDER BY
    mv ASC,
    DATE_FORMAT(wp_posts.post_date,'%Y-%m-%d') DESC
    "
    

    dove $queried_object è il risultato di "$queried_object = get_queried_object();" utile per prendermi dei dati che mi servono.

    Come posso utilizzare questa query nella funzione sopra riportata?? è possibile parametrizzare la query per utilizzare i metodi

    nativi di wordpress per ricavarne i risultati? Vorrei avere lo stesso risultato in entrambi i casi così da non dover modificare

    ulteriormente il codice di stampa per i risultati...

    Grazie in anticipo, saluti.

  • Accedi

  • Non hai un account? Registrati

  • Accedi o registrati per effettuare la ricerca.
  • Primo post
    Ultimo post
Home Accedi Registrati
Menu
  • CATEGORIES
  • La Community Connect.gt
  • Presentati alla Community
  • News Ufficiali da Connect.gt
  • Internet News
  • A Scuola Di
  • Digital Marketing
  • Intelligenza Artificiale
  • SEO & GEO
  • Web Marketing e Content
  • Google Analytics e Web Analytics
  • Google Ads & Advertising
  • YouTube
  • TikTok, Instagram e altri Social
  • Google Adsense, Affiliazioni e Guadagno
  • E-Commerce
  • Coding e Sistemistica
  • Help Center: consigli per il tuo progetto
  • Hosting e Cloud
  • Coding
  • CMS & Piattaforme Self-Hosted
  • Annunci e Collaborazioni
  • Annunci Vendita e Acquisto: Pubblicità, Domini, Link e altro
  • Collaborazioni WEB e Lavoro: offro e cerco
  • Impresa, Fisco e Leggi
  • Consulenza Legale e Professioni Web
  • Consulenza Fiscale, Imprese, Startup e P.Iva
  • Gli Off Topic
  • PC, Smartphone e altri Hardware
  • Tutti i Software
  • GT Fetish Cafè
  • Discussioni
  • Non letti 0
  • Recenti
  • Hashtag
  • Popolare
  • Utenti
  • Privacy
  • Termini e condizioni
  • © 2026 Search On Media Group S.r.l.