Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can easily insert more elements - as you did. The part that won't work is adding an element that doesn't exist on the page. </p> <p>For a WordPress post to 'exist' on the page, it has to be queried by PHP in some way.</p> <p>You can use a custom query - like you did using WP_Query(): <a href="http://codex.wordpress.org/Class_Reference/WP_Query" rel="nofollow">http://codex.wordpress.org/Class_Reference/WP_Query</a></p> <p>You can also use something like get_posts: <a href="http://codex.wordpress.org/Template_Tags/get_posts" rel="nofollow">http://codex.wordpress.org/Template_Tags/get_posts</a></p> <p>But unless you queried them through WP somehow, they don't exist on the page and can't be added at runtime.</p> <p>You could do a separate query for the extra posts you want and put them in a div with the CSS set to display:none</p> <p>That way, you could reference them with your JS because they would exist on the page. </p> <p>Something like this:</p> <pre><code>global $post; //First Query $args = array( 'post_type' =&gt; "post", 'tax_query' =&gt; array( 'relation' =&gt; 'AND', array( 'taxonomy' =&gt; 'category', 'field' =&gt; 'id', 'terms' =&gt; 'my_category_name, 'operator' =&gt; 'IN' ) ) ); $posts_main_group = get_posts($args); foreach($posts_main_group as $post) : ?&gt;&lt;div class="&lt;?php post_class(); ?&gt;" style="block;"&gt;&lt;?php the_title(); ?&gt;&lt;/div&gt;&lt;?php endforeach; //Second hidden query $args = array( 'post_type' =&gt; "post", 'tax_query' =&gt; array( 'relation' =&gt; 'AND', array( 'taxonomy' =&gt; 'category', 'field' =&gt; 'id', 'terms' =&gt; 'my_hidden_category_name_with_extra_posts, 'operator' =&gt; 'IN' ) ) ); $posts_extra_group = get_posts($args); foreach($posts_extra_group as $post) : ?&gt;&lt;div class="&lt;?php post_class(); ?&gt;" style="display:none;"&gt;&lt;?php the_title(); ?&gt;&lt;/div&gt;&lt;?php endforeach; </code></pre> <p>This way, you can target the hidden divs with jquery and add them - now that they exist on the page.</p> <p>Also note, I did the CSS inline for simplicity's sake in the example - but you should use a stylesheet to do that if possible.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload