Title: Problem with &#039;offset&#039; and &#039;numberposts&#039; while using get_posts() ?
Last modified: August 20, 2016

---

# Problem with 'offset' and 'numberposts' while using get_posts() ?

 *  Resolved [caratage](https://wordpress.org/support/users/caratage/)
 * (@caratage)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/problem-with-offset-and-numberposts-while-using-get_posts/)
 * Loving the plugin and using it regularly. But just now a ran into a problem and
   I seem not to find the solution. Probably it’s very easy.
 * I wrote a function in functions.php that allows me to display connected staff
   on different pages. Sometimes I need to display all or only one connection and
   there will be an offset to display the first connection differently:
 *     ```
       function show_connected_staff($offset, $numberposts) {
       	// Find connected posts
       	$args = array(
       		'connected_type' => 'staff_to_pages',
       		'connected_items' => get_queried_object(),
       		'nopaging' => true,
       		'suppress_filters' => true,
       		'connected_query' => array(
       			'offset' => $offset,
       			'numberposts' => $numberposts,
       		),
       	);
       	$persons = get_posts($args);
       	// Display connected posts
       	if ($persons) {
       		foreach($persons as $person) {
       			echo $person->post_title;
       		} // end foreach
       	} // end if
       } // end show_connected_staff
       ```
   
 * Connections are set up properly, I can see all the data properly. Only problem
   is that the arguments are not passed to the function.
 * So calling `<?php show_connected_staff(1, 1); ?>` or `<?php show_connected_staff(
   0, 999); ?>` in my theme will always display all connected items regardless of
   value of the arguments.
 * Suggestions?
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [caratage](https://wordpress.org/support/users/caratage/)
 * (@caratage)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/problem-with-offset-and-numberposts-while-using-get_posts/#post-3522940)
 * OK, go figure: [https://github.com/scribu/wp-posts-to-posts/wiki/Query-vars](https://github.com/scribu/wp-posts-to-posts/wiki/Query-vars).
 * Seems like native WordPress query variables do not work on `connected_items`.
 * Thought again and found some other solution to my problem.
    Thanks anyway Scribu
   for the excellent plugin.
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/problem-with-offset-and-numberposts-while-using-get_posts/#post-3522941)
 * > Seems like native WordPress query variables do not work on connected_query.
 * Yes, they do, except for the ones related to pagination, since they don’t make
   sense there.
 * You probably wanted to put them outside the ‘connected_query’ anyway.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Problem with 'offset' and 'numberposts' while using get_posts() ?’ is
closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/posts-to-posts_7a8e9d.svg)
 * [Posts 2 Posts](https://wordpress.org/plugins/posts-to-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/posts-to-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/posts-to-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/posts-to-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/posts-to-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/posts-to-posts/reviews/)

## Tags

 * [get_posts](https://wordpress.org/support/topic-tag/get_posts/)
 * [offset](https://wordpress.org/support/topic-tag/offset/)
 * [posts-2-posts](https://wordpress.org/support/topic-tag/posts-2-posts/)

 * 2 replies
 * 2 participants
 * Last reply from: [scribu](https://wordpress.org/support/users/scribu/)
 * Last activity: [13 years, 2 months ago](https://wordpress.org/support/topic/problem-with-offset-and-numberposts-while-using-get_posts/#post-3522941)
 * Status: resolved