Home Forums Front-end Issues Use 'Page Link'-field as parameter for a query


Use 'Page Link'-field as parameter for a query

  • Hi everyone,

    I am trying to filter a WP_query by a “Page Link”-field. This is the code I have, but it doesn’t output any posts.

    The same code works with a different field type, for example test.

    Any idea what I am missing?

    Thanks in advance!

    $current_url = get_permalink();
    echo $current_url;
    $args = array(
      'numberposts'	   => -1,
      'category_name'  => 'events',
      'post_type'	   => 'post',
      'meta_key'	   => 'page_link',
      'meta_value'	   => $current_url
    // the query
    $the_query = new WP_Query( $args );
  • The page link field stores a post id when a page or post is selected and the URL when an archive page is selected.

    Before you can do a query you need to know what the post_id is if you’re looking for a post, or alternately you need to know it’s an archive page. If you on a post page then you could probably just use $post->ID.

  • Thanks John!

    That solved the problem, even on archive pages.

    I did not know that the link field stored the post_id. I must have missed that in the documentation.

    Now I can cross link locations and events solely by providing a link to the location in every event post.

    Thanks again!

  • There isn’t documentation on how all of the fields are stored in the database. What I did was I looked in the database for one of my sites that uses the page link field to see what was in there. I’m sure I’ve looked before as well but it’s not always easy to remember.

  • Aaah right, should have checked the database. But a small info for each field type about what is stored in the database might be helpful.

    Thanks again!

  • Hopefully with Elliot getting some help in developement the documentation will get a little more attention.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.