1

Je veux quelque chose pour m’aider à créer automatiquement un article avec 10 dernières images hébergées dans un répertoire (sur mon serveur ou wordpress), ce code m’a aidé à poster une image, mais pas plusieurs images, si quelqu’un pouvait m’aider ..

je ne suis pas un développeur php .. mais j’ai besoin de cette solution

<code><span class="pln">add_action</span><span class="pun">(</span><span class="str">'add_attachment'</span><span class="pun">,</span> <span class="str">'create_post'</span><span class="pun">);</span>
    <span class="kwd">function</span><span class="pln"> create_post</span><span class="pun">(</span><span class="pln"> $attach_ID </span><span class="pun">)</span> <span class="pun">{</span><span class="pln">

    $attachment </span><span class="pun">=</span><span class="pln"> get_post</span><span class="pun">(</span><span class="pln"> $attach_ID </span><span class="pun">);</span><span class="pln">

    $my_post_data </span><span class="pun">=</span><span class="pln"> array</span><span class="pun">(</span>
                <span class="str">'post_title'</span> <span class="pun">=></span><span class="pln"> $attachment</span><span class="pun">-></span><span class="pln">post_title</span><span class="pun">,</span>
                <span class="str">'post_type'</span> <span class="pun">=></span> <span class="str">'post'</span><span class="pun">,</span>
                <span class="str">'post_category'</span> <span class="pun">=></span><span class="pln"> array</span><span class="pun">(</span><span class="str">'0'</span><span class="pun">),</span>
                <span class="str">'post_status'</span> <span class="pun">=></span> <span class="str">'publish'</span>
    <span class="pun">);</span><span class="pln">
    $post_id </span><span class="pun">=</span><span class="pln"> wp_insert_post</span><span class="pun">(</span><span class="pln"> $my_post_data </span><span class="pun">);</span>

    <span class="com">// attach media to post</span><span class="pln">
    wp_update_post</span><span class="pun">(</span><span class="pln"> array</span><span class="pun">(</span>
        <span class="str">'ID'</span> <span class="pun">=></span><span class="pln"> $attach_ID</span><span class="pun">,</span>
        <span class="str">'post_parent'</span> <span class="pun">=></span><span class="pln"> $post_id</span><span class="pun">,</span>
    <span class="pun">)</span> <span class="pun">);</span><span class="pln">

    set_post_thumbnail</span><span class="pun">(</span><span class="pln"> $post_id</span><span class="pun">,</span><span class="pln"> $attach_ID </span><span class="pun">);</span>

    <span class="kwd">return</span><span class="pln"> $attach_ID</span><span class="pun">;</span>
<span class="pun">}</span></code>
Asked question