Obtenir le contenu du message par ID
-
-
Votes défavorables car vousn'avezmêmepasessayé de lire les documents sur `get_page ()`.Ilest obsolète depuistrès longtemps.En outre,ilexiste une quantitéillimitée de ressources sur le site concernant ceproblème,même Google a destonnes d'informations à ce sujetDownvotes 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 réponses
- votes
-
- 2016-01-06
Vouspouvez lefaire deplusieursmanières. Voici les deuxmeilleuresfaçons.
$post_id = 5// example post id $post_content = get_post($post_id); $content = $post_content->post_content; echo do_shortcode( $content );//executing shortcodes
Une autreméthode
$content = get_post_field('post_content', $post_id); echo do_shortcode( $content );//executing shortcodes
Après la suggestion de Pieter Goosen sur
apply_filters
.Vouspouvez utiliser
apply_filters
si vous souhaitez que le contenu soitfiltrépar d'autresplugins. Cela élimine donc lebesoin d'utiliserdo_shortcode
Exemple
$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.
Si vousne souhaitezpas autoriser d'autresplugins àfiltrer ce contenuet que vous avezbesoin d'unefonction de shortcode,utilisez
do_shortcode
.Si vousne voulezpastrop de shortcode,jouez simplement avec le
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
.-
Jeme demande simplementpourquoi vous utilisez `do_shortcode`Just wonder why you are using `do_shortcode`
- 0
- 2016-01-06
- Pieter Goosen
-
Salutmerci d'avoir demandé.@PieterGoosen Commenous obtenons le «contenubrut» dumessage.Tout code courtintégré dans lapublicationne serapastraité.doncnous lefaisonsnous-mêmes avec `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
-
Unemeilleurefaçon serait d'utiliser `apply_filters ('the_content',$ content);`,de cettefaçon,tous lesfiltres appliqués à `the_content ()` comme `wpautop`et legestionnaire de shortcode,sont appliqués à` $ content`.;-).Notez lepluriel `filters`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
-
Oui,utiliser `apply_filters` au lieu de` do_shortcode` a du sens.Mais utiliser `apply_filter`estpurementbasé sur leur décision d'environnement.Permettez-moi également demettre àjourma réponse.Mercibeaucouppour votre attention sur la communauté @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
Je vaisjuste laisserici une autrefaçon hackyet laide que vouspourrieztrouver utileparfois.Bien sûr,lesméthodes qui utilisent des appels d'API sonttoujourspréférées (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);
-
Veuillez ** [modifier] votre réponse **,et ajouter uneexplication: **pourquoi ** celapourrait-il résoudre leproblème?Please **[edit] your answer**, and add an explanation: **why** could that solve the problem?
- 1
- 2018-01-19
- fuxia
-
- 2016-01-06
En utilisant
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;
-
Évalué car vousn'avezmêmepas vraimentessayé de lire la documentation.`get_page ()`est dépréciéDownvoted as you really did not even tried to read the documentation. `get_page()` is depreciated
- 1
- 2016-01-06
- Pieter Goosen
Commentpuis-je obtenir le contenu d'un articleparidentifiant d'article?J'aiessayé
get_page('ID');
pour afficher le contenumais celane fonctionnepas.