2016-09-19 2 views
0

Ich verwende einen Shortcode, um den Inhalt einer Seite zu erhalten. Der Shortcode läuft gut, wenn er im wp-Editor hinzugefügt wird, aber es scheint nicht zu funktionieren oder besser, ich sage, es wird nicht geparst, wenn es über Ajax kommt.Wie man Inhalte über den Shortcode in Ajax holt

Ich habe ein Popup auf der Website, die WooCommerce Produktinfo über Ajax anzeigt. Der Shortcode zeigt nur Rohcodes und wird nicht geparst. Dies ist der Short

function fetch_content_shortcode($atts, $content = null) 
{ 
    global $post; 
    extract(shortcode_atts(array(
     'id' => null 
    ), $atts)); 
    ob_start(); 
    $output = apply_filters('the_content', get_post_field('post_content', $id)); 
    $output .= ob_get_contents(); 
    ob_end_clean(); 
    return $output; 
} 

add_shortcode('fetch-content', 'fetch_content_shortcode'); 

Die Short [fetch-content id="1234"] funktioniert gut, wenn sie in einem Texteditor hinzugefügt, aber nicht mit Ajax. Jede Hilfe wird dankbar sein.

+0

es funktioniert hier in Ajax gut. kannst du mir bitte eine Demo-URL schicken? –

+0

Danke Mukesh. Bitte beachten Sie diese beiden URLs https://ayanize.com/dev1/ (Klicken Sie auf die Schaltfläche Quick Look) und diese URL https://ayanize.com/dev1/product/demo-product/. Das Bild des Mannes, der das Ohr hält, ist der Inhalt, der von einer Seiten-ID abgerufen wird, die nicht angezeigt wird, wenn auf die Schaltfläche "Quick Look" geklickt wird. – Ayanize

Antwort

0

Für Produkt "Produktkurzbeschreibung" ist Inhalt des Produktes nicht, wenn Sie dieses Feld erhalten möchten, dann fügen Sie unter dem Code hinzu.

/* If you want content of page, post or product */ 
$output = apply_filters('the_content', get_post_field('post_content', $id)); 
/* If you want excerpt of page, post or product */ 
$output = apply_filters('the_excerpt', get_post_field('post_excerpt', $id)); 

Shortcode to get product excerpt: 

function fetch_content_shortcode($atts, $content = null) { 
    global $post; 
    extract(shortcode_atts(array(
     'id' => null 
    ), $atts)); 
    ob_start(); 
    /* If you want excerpt of page, post or product */ 
    $output = apply_filters('the_excerpt', get_post_field('post_excerpt', $id)); 
    $output .= ob_get_contents(); 
    ob_end_clean(); 
    return $output; 
} 
add_shortcode('fetch-content', 'fetch_content_shortcode'); 

Dieser Code ist getestet und funktioniert einwandfrei.

+0

Danke dafür, aber das ist nicht der Punkt hier. Der Shortcode holt tatsächlich Post-Inhalt, aber dieser wird in einem Auszug hinzugefügt, wie Sie sehen können. Es funktioniert auf der einzelnen Produktseite, wo es in WC kurze Beschreibung Box hinzugefügt wird, aber nicht die Divi shortcodes zu analysieren, wenn sie im Ajax Popup – Ayanize

+0

aufgerufen werden, um einen Auszug zu erhalten, dass Code auch in Ajax funktioniert –