• Hi,

    I am new to wordpress. I want to fetch the posts created by the plugin from php. I tried to use query_posts(), but it only returns the post created by wordpress admin not the third party plugin.

    The URL for the post I want to find from php:
    https://smap.cas.mcmaster.ca/wp-admin/post.php?post=1035&action=edit
    The URL for the post that can be returned byquery_posts():
    https://smap.cas.mcmaster.ca/wp-admin/post.php?post=1005&action=edit

    The only difference is the post id. If they are save in the same place, why the query_posts() cannot return the first one?

    Thanks a lot!

    • This topic was modified 3 years, 7 months ago by cchzhu.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @cchzhu,

    You should pass accurate parameter for custom code.
    Such as:
    query_posts(‘post_type=product’);

    Please replace your post_type: product to ‘your post type

    I hope it will work for you.

    Thanks

    Moderator bcworkz

    (@bcworkz)

    FYI – query_posts() is inefficient because it discards the original main query which has already been done and starts a new query. You’re better off using the “pre_get_posts” action to set the main query’s query vars as you need instead of using query_posts().

    To get custom posts queried through “pre_get_posts”, if the passed query object is collected as $query, you’d do
    $query->set('post_type', 'product'); // or whatever your post type really is
    from within the action callback.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘query_posts() Cannot find posts created by plugin.’ is closed to new replies.