Ottieni il contenuto del post per ID
-
-
Downvotesperchénon hainemmenoprovato a leggerei documenti su `get_page ()`.È stato deprecatomoltotempofa.Inoltre,ci sono una quantitàillimitata di risorse sul sitoper quanto riguarda questoproblema,anche Google hatonnellate diinformazioni su questoDownvotes as you did not even try to read the docs on `get_page()`. It has been deprecited a very long time ago. Also, there are an unlimited amount of resources on site regarding this issue, even google has tons of info on this
- 1
- 2016-01-06
- Pieter Goosen
-
4 risposta
- voti
-
- 2016-01-06
Puoifarloin diversimodi. I seguenti sonoi duemodimigliori.
$post_id = 5// example post id $post_content = get_post($post_id); $content = $post_content->post_content; echo do_shortcode( $content );//executing shortcodes
Un altrometodo
$content = get_post_field('post_content', $post_id); echo do_shortcode( $content );//executing shortcodes
Dopoil suggerimento di Pieter Goosen su
apply_filters
.Puoi utilizzare
apply_filters
se desideri cheil contenuto vengafiltrato da altriplugin. Quindi questoelimina lanecessità di utilizzaredo_shortcode
Esempio
$post_id = 5// example post id $post_content = get_post($post_id); $content = $post_content->post_content; echo apply_filters('the_content',$content); //no need to use do_shortcode, but content might be filtered by other plugins.
Senon vuoi consentire ad altriplugin difiltrare questo contenutoe haibisogno dellafunzione shortcode,scegli
do_shortcode
.Senon vuoi anche lo shortcode,gioca con
post_content
.You can do it multiple ways. Following are best two ways.
$post_id = 5// example post id $post_content = get_post($post_id); $content = $post_content->post_content; echo do_shortcode( $content );//executing shortcodes
Another method
$content = get_post_field('post_content', $post_id); echo do_shortcode( $content );//executing shortcodes
After Pieter Goosen suggestion on
apply_filters
.You can use
apply_filters
if you wanted the content to be filtered by other plugins. So this eliminates the need to usedo_shortcode
Example
$post_id = 5// example post id $post_content = get_post($post_id); $content = $post_content->post_content; echo apply_filters('the_content',$content); //no need to use do_shortcode, but content might be filtered by other plugins.
If you don't want to allow other plugins to filter this content and need shortcode function then go with
do_shortcode
.If you don't want shortcode too then just play with the
post_content
.-
Mi chiedo soloperché stai usando "do_shortcode"Just wonder why you are using `do_shortcode`
- 0
- 2016-01-06
- Pieter Goosen
-
Ciaograzieper averlo chiesto.@PieterGoosen Poiché stiamo ottenendoil "contenutogrezzo" delpost.Qualsiasi shortcodeincorporatonelpostnon verràelaborato.quindi lo stiamofacendo da soli con `do_shortcode`Hi thanks for asking. @PieterGoosen As we are getting the `raw content` of post. Any shortcode embedded in the post won't be processed. so we are doing that by ourself with `do_shortcode`
- 0
- 2016-01-06
- WPTC-Troop
-
Unmodomigliore sarebbe usare `apply_filters ('the_content',$ content);`,in questomodo,tuttii filtri che sono applicati a `the_content ()` come `wpautop`e ilgestore dello shortcode,vengono applicati a` $ content`.;-).Notailplurale "filtri"A better way would be to use `apply_filters( 'the_content', $content );`, this way, all filters that are applied to `the_content()` like `wpautop` and the shortcode handler, is applied to `$content`. ;-). Note the plural `filters`
- 2
- 2016-01-06
- Pieter Goosen
-
Sì,ha senso usare `apply_filters`invece di` do_shortcode`.Ma l'uso di `apply_filter` èbasatoesclusivamente sulla loro decisione ambientale.Permettimi di aggiornare anche lamia risposta.Graziemilleper latua attenzione alla community @PieterGoosenYes, using `apply_filters` instead of `do_shortcode` make sense. But using `apply_filter` is purely based on their environment decision. Let me update my answer too. Thank you so much for your care on community @PieterGoosen
- 1
- 2016-01-06
- WPTC-Troop
-
- 2016-11-19
Lascerò qui un altromodomaliziosoe brutto che a voltepotrestitrovare utile.Ovviamentei metodi che utilizzano le chiamate API sono semprepreferiti (get_post (),get_the_content (),...).
global $wpdb; $post_id = 123; // fill in your desired post ID $post_content_raw = $wpdb->get_var( $wpdb->prepare( "select post_content from $wpdb->posts where ID = %d", $post_id ) );
I'll just leave here another hacky ugly way that you may find useful sometimes. Of course methods which use API calls are always preferred (get_post(), get_the_content(), ...).
global $wpdb; $post_id = 123; // fill in your desired post ID $post_content_raw = $wpdb->get_var( $wpdb->prepare( "select post_content from $wpdb->posts where ID = %d", $post_id ) );
-
- 2018-01-19
$id = 23; // add the ID of the page where the zero is $p = get_page($id); $t = $p->post_title; echo '<h3>'.apply_filters('post_title', $t).'</h3>'; // the title is here wrapped with h3 echo apply_filters('the_content', $p->post_content);
$id = 23; // add the ID of the page where the zero is $p = get_page($id); $t = $p->post_title; echo '<h3>'.apply_filters('post_title', $t).'</h3>'; // the title is here wrapped with h3 echo apply_filters('the_content', $p->post_content);
-
Perfavore ** [modifica] latua risposta **e aggiungi una spiegazione: **perché ** questopotrebbe risolvereilproblema?Please **[edit] your answer**, and add an explanation: **why** could that solve the problem?
- 1
- 2018-01-19
- fuxia
-
- 2016-01-06
Utilizzando
get_page('ID')
.$page_id = 123; //Page ID $page_data = get_page($page_id); $title = $page_data->post_title; $content = $page_data->post_content;
By using
get_page('ID')
.$page_id = 123; //Page ID $page_data = get_page($page_id); $title = $page_data->post_title; $content = $page_data->post_content;
-
Downvoted come davveronon hainemmenoprovato a leggere la documentazione."get_page ()" è deprezzatoDownvoted as you really did not even tried to read the documentation. `get_page()` is depreciated
- 1
- 2016-01-06
- Pieter Goosen
Comeposso ottenereil contenuto di unposttramite l'ID delpost?Hoprovato
get_page('ID');
permostrareil contenutomanonfunziona.