Obtenir le contenu de l'article WordPress par identifiant de l'article
4 réponses
- votes
-
- 2011-02-17
Aussi simple que celapuisse être
$my_postid = 12;//This is page id or post id $content_post = get_post($my_postid); $content = $content_post->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); echo $content;
Simple as it gets
$my_postid = 12;//This is page id or post id $content_post = get_post($my_postid); $content = $content_post->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); echo $content;
-
Raccourcipour un champ spécifique: `$ content=get_post_field ('post_content',$my_postid);`Shorthand for specific field: `$content = get_post_field('post_content', $my_postid);`
- 89
- 2011-02-17
- Rarst
-
@Bainternet Je suisjuste curieuxici ... quelleest lapartie `$ content=str_replace (']]>',']] >',$ content);`faire?quelest lebut là-bas?@Bainternet I'm just curious here... what is the part `$content = str_replace(']]>', ']]>', $content);` do? what's the purpose of it there?
- 5
- 2013-11-04
- Average Joe
-
@AverageJoe sa recherche debaseet remplace.Lors de l'utilisation dethe_content (),le contenuestfiltré.Comme dans l'exemple ci-dessus,le contenu a été directement récupéré,l'auteur a utilisé la rechercheet le remplacementpour le rendre sûr.@AverageJoe its basic search and replace. When using the_content() the content is filtered. Since in the above example the content was directly retrieved, the author has used the search and replace to make it safe.
- 2
- 2014-03-18
- Harish Chouhan
-
peut-être avez-vous aussibesoin de do_shortcode () comme `$ content=do_shortcode (get_post_field ('post_content',$my_postid));`maybe you also need do_shortcode() like `$content = do_shortcode(get_post_field('post_content', $my_postid));`
- 3
- 2018-03-09
- cyptus
-
Est-ilpossible de conserver le "more_link"?Is there anyway to preserve the "more_link"?
- 0
- 2018-07-05
- user2128576
-
- 2012-10-05
echo get_post_field('post_content', $post_id);
echo get_post_field('post_content', $post_id);
-
mieux vaut lefaire comme `echo apply_filters ('the_content',get_post_field ('post_content',$post_id));`.Parexemple,lors de l'utilisation de qTranslate,votre solutionne seraitpas suffisante.better to do it like `echo apply_filters('the_content', get_post_field('post_content', $post_id));`. For example when using qTranslate, your solution would not be enough.
- 64
- 2013-01-17
- Karel Attl
-
C'est lameilleure réponse si l'objectifest d'obtenir le contenu de l'articletel qu'ilest dans lapage d'édition de WordPress.This is the best answer if the scope is to get the post content as it is in the WordPress edit page.
- 5
- 2014-08-08
- mcont
-
Sans le code de @KarelAttl,les sauts de ligne étaientmanquants.Avec le code apply_filters,celafonctionnaitparfaitement.Without the code from @KarelAttl line breaks where missing. With the apply_filters code it worked perfectly.
- 1
- 2015-09-23
- Alexander Taubenkorb
-
`apply_filters`est unebonne option,maisne correspondaitpas àmon objectif actuel.C'estbien d'avoir les deux options.`apply_filters` is a good option, but wasn't right for my current purpose. It's good to have both options.
- 2
- 2015-11-05
- KnightHawk
-
- 2016-12-02
Une autrefaçon d'obtenir le contenu d'un article WordPressparidentifiant d'articleest:
$content = apply_filters('the_content', get_post_field('post_content', $my_postid));
Pour compléter cette réponse,j'ai également ajouté laméthode 01et laméthode 02 à cette réponse.
Méthode 01 (lemérite revient à bainternet ):
$content_post = get_post($my_postid); $content = $content_post->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content);
Méthode 02 (lemérite revient à realmag777 ):
$content = get_post_field('post_content', $my_postid);
Méthode 03:
$content = apply_filters('the_content', get_post_field('post_content', $my_postid));
Lisez le Quelest lemoyen lemeilleur/efficacepour obtenir du contenu WordPressparidentifiant depublicationet pourquoi? questionpour avoir uneidée de celui que vous devriez utiliserparmi lestrois ci-dessus.
Another way to get a WordPress post content by post id is:
$content = apply_filters('the_content', get_post_field('post_content', $my_postid));
To complete this answer I have also added method 01 and method 02 to this answer.
Method 01 (credit goes to bainternet):
$content_post = get_post($my_postid); $content = $content_post->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content);
Method 02 (credit goes to realmag777):
$content = get_post_field('post_content', $my_postid);
Method 03:
$content = apply_filters('the_content', get_post_field('post_content', $my_postid));
Read the What is the best / efficient way to get WordPress content by post id and why? question to get an idea about which one you should use from the above three.
-
- 2015-11-20
Si vous avezbesoin deplus d'unmessage,utilisez
get_posts()
.Il laisse la requêteprincipale seuleet renvoie untableau demessagesfaciles àparcourir.If you need more than one post, use
get_posts()
. It leaves the main query alone and returns an array of posts that's easy to loop over.
Commentpuis-je obtenir du contenu depublication WordPressparidentifiant depublication?