Holen Sie sich Post-Inhalt von ID
-
-
Downvotes,da Sienichteinmal versucht haben,die Dokumente auf `get_page ()` zu lesen.Es wurde vor sehr langer Zeit abgeschrieben.Außerdemgibt es vor Orteine unbegrenzte Anzahl von Ressourcen zu diesem Thema,selbst Google hat unzählige Informationen dazuDownvotes 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 Antworten
- Stimmen
-
- 2016-01-06
Sie können dies aufmehrere Artentun. Im Folgendenfinden Sie diebesten zwei Möglichkeiten.
$post_id = 5// example post id $post_content = get_post($post_id); $content = $post_content->post_content; echo do_shortcode( $content );//executing shortcodes
Eine andere Methode
$content = get_post_field('post_content', $post_id); echo do_shortcode( $content );//executing shortcodes
Nach dem Vorschlag von Pieter Goosen zu
apply_filters
.Sie können
apply_filters
verwenden,wenn der Inhalt von anderen Pluginsgefiltert werden soll. Dadurchentfällt die Verwendung vondo_shortcode
Beispiel
$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.
Wenn Sienichtmöchten,dass andere Plugins diesen Inhaltfiltern undeine Shortcode-Funktionbenötigen,wählen Sie
do_shortcode
.Wenn Sie auch keinen Shortcodemöchten,spielen Sieeinfachmit dem
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
.-
Fragen Sie sichnur,warum Sie "do_shortcode" verwendenJust wonder why you are using `do_shortcode`
- 0
- 2016-01-06
- Pieter Goosen
-
Hallo,danke,dass dugefragt hast.@PieterGoosen Da wir den "Rohinhalt" der Postbekommen.In den Beitrageingebettete Shortcodes werdennicht verarbeitet.Alsomachen wir das alleinemit `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
-
Einbesserer Weg wäre,"apply_filters" ("the_content",$ content) zu verwenden. Auf diese Weise werden alle Filter,die auf "the_content ()" wie "wpautop" und den Shortcode-Handler angewendet werden,auf "$ content" angewendet.;-).Beachten Sie den Plural "Filter"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
-
Ja,die Verwendung von "apply_filters" anstelle von "do_shortcode"ist sinnvoll.Die Verwendung von "apply_filter"basiertjedoch ausschließlich aufihrer Umgebungsentscheidung.Lassen Siemich auchmeine Antwort aktualisieren.Vielen Dankfür Ihre Fürsorgein der 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
Ich lasse hiereinfacheinen anderen hässlichen Weg,den Siemanchmalnützlichfinden.Natürlich werdenimmer Methodenbevorzugt,die API-Aufrufe verwenden (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);
-
Bitte ** [bearbeiten] Sie Ihre Antwort ** undfügen Sieeine Erklärung hinzu: ** Warum ** könnte das das Problem lösen?Please **[edit] your answer**, and add an explanation: **why** could that solve the problem?
- 1
- 2018-01-19
- fuxia
-
- 2016-01-06
Mit
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,da Sie wirklichnichteinmal versucht haben,die Dokumentation zu lesen.get_page () wird abgeschriebenDownvoted as you really did not even tried to read the documentation. `get_page()` is depreciated
- 1
- 2016-01-06
- Pieter Goosen
Wie kannich den Inhalteines Beitrags anhand der Beitrags-ID abrufen?Ich habe versucht,
get_page('ID');
,um Inhalte anzuzeigen,aberesfunktioniertnicht.