WordPress.org

Ready to get started?Download WordPress

Forums

Get page content manually (4 posts)

  1. diogomend
    Member
    Posted 2 years ago #

    Good afternoon, i am having a big trouble on solving this issue.
    I want to access the php code and BEFORE the page is displayed, i want to get the $_GET parameter and access the Database to check the page_id for that parameter.
    For instance: /wordpress?paramenter=sitename and in my DB i can relate that sitename to a page_id.
    Is it possible? Pleaaase :)

  2. vtxyzzy
    Member
    Posted 2 years ago #

    Where would sitename and its relation to a page ID be stored in the database?

    For example, you could have a Custom Field called 'sitename' with the value of the actual site name, attached to the proper page/post.

    Then you could use a WP_Query on meta_key => 'sitename' and meta_value => $sitename to return the page/post. Something like this (not an example of bulletproof code!):

    $sitename = $_GET['parameter'];
    $args = array(
       'posts_per_page' => 1,
       'ignore_sticky_posts' => 1,
       'meta_key' => 'sitename',
       'meta_value' => $sitename,
    );
    $my_post = new WP_Query($args);
  3. diogomend
    Member
    Posted 2 years ago #

    Hello vtxyzzy,
    that should do it, but where do I put that piece of code? In the templateloader.php? I think that is the file responsible to get the page content

  4. vtxyzzy
    Member
    Posted 2 years ago #

    Where you put the code depends totally on your theme.

    If you are using a free theme, post a link here to its download page so the code can be examined. If you are using a paid theme, you should contact the theme supplier.

Topic Closed

This topic has been closed to new replies.

About this Topic