douhan9619 2019-03-04 11:01
浏览 44

自定义分类法帖子页面中的帖子

I'm trying to troubleshoot a website that uses custom taxonomies to show certain posts in custom post page. The problem is they are not showing. I found this code in the page where they should appear but I can't figure out if it's ok or not:

$url = wp_get_attachment_url( get_post_thumbnail_id($post_id) );
// $terms = get_the_terms( $post_id, 'tipologia-servizio');
$term_list_tipo_servizi = wp_get_post_terms($post_id, 'tipologia-servizio', 
array("fields" => "ids"));
// $term_id = array_pop($terms);
// $term_name = $term_id->name;
// $term_slug = $term_id->slug;

$query_args = array(
  'post_type' => array('servizio'),
  'showposts' => 10,
   'tax_query' => array(
         'relation' => 'AND',
        array(
          'taxonomy' => 'tipologia-servizio',                //(string) - Taxonomy.
          'field' => 'id',                    //(string) - Select taxonomy term by ('id' or 'slug')
          'terms' => $term_list_tipo_servizi,    //(int/string/array) - Taxonomy term(s).
          'include_children' => true                   //(string) - Operator to test. Possible values are 'IN', 'NOT IN', 'AND'.
        )
    )
 );

The only thing that came up in my mind was to see if exclude_from_search in the custom post type function was set to true and maybe turn it to false but it was false already.

EDIT: This is the custom post type function:

function confesercenti_custom_post() {

    register_post_type( 'servizio', /* nome del custom post type */
    // aggiungiamo ora tutte le impostazioni necessarie, in primis definiamo le varie etichette mostrate nei menù
    array('labels' => array(
        'name' => 'Servizi', /* Nome, al plurale, dell'etichetta del post type. */
        'singular_name' => 'Servizio', /* Nome, al singolare, dell'etichetta del post type. */
        'all_items' => 'Tutti i Servizi', /* Testo mostrato nei menu che indica tutti i contenuti del post type */
        'add_new' => 'Aggiungi nuovo', /* Il testo per il pulsante Aggiungi. */
        'add_new_item' => 'Aggiungi Nuovo Servizio', /* Testo per il pulsante Aggiungi nuovo post type */
        'edit_item' => 'Modifica Servizio', /*  Testo per modifica */
        'new_item' => 'Nuova Servizio', /* Testo per nuovo oggetto */
        'view_item' => 'Vedi Servizio', /* Testo per visualizzare */
        'search_items' => 'Cerca Servizio', /* Testo per la ricerca*/
        'not_found' =>  'Nessun Servizio trovato', /* Testo per risultato non trovato */
        'not_found_in_trash' => 'Nessun Servizio trovato nel Cestino', /* Testo per risultato non trovato nel cestino */
        'parent_item_colon' => ''
        ), /* Fine dell'array delle etichette */
              'taxonomies' => array('category','post_tag'),
        'description' => 'I Servizi offerti da Confesercenti Pistoia', /* Una breve descrizione del post type */
        'public' => true, /* Definisce se il post type sia visibile sia da front-end che da back-end */
        'publicly_queryable' => true, /* Definisce se possono essere fatte query da front-end */
        'exclude_from_search' => false, /* Definisce se questo post type è escluso dai risultati di ricerca */
        'show_ui' => true, /* Definisce se deve essere visualizzata l'interfaccia di default nel pannello di amministrazione */
        'query_var' => true,
        'menu_position' => 6, /* Definisce l'ordine in cui comparire nel menù di amministrazione a sinistra */
        'menu_icon' => 'dashicons-star-half', /* Scegli l'icona da usare nel menù per il post type */
        'rewrite'   => array( 'slug' => 'servizio', 'with_front' => false ), /* Puoi specificare uno slug per gli URL */
        'has_archive' => 'servizio', /* Definisci se abilitare la generazione di un archivio (equivalente di archive-libri.php) */
        'capability_type' => 'post', /* Definisci se si comporterà come un post o come una pagina */
        'hierarchical' => false, /* Definisci se potranno essere definiti elementi padri di altri */
        /* la riga successiva definisce quali elementi verranno visualizzati nella schermata di creazione del post */
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'sticky')
    ) /* fine delle opzioni */
); /* fine della registrazione */
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Oracle触发器记录修改前后的字段值
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器