• I’m making a “Print This Page” button, and I want to use the “Get_post()” function to grab the contents of the current post and stuff it into a file that I can print.

    BUT… I cannot find the Get_post() function. I’ve done test searches throughout the WP files, and cannot find it.

    Can anyone tell me where it is?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • https://codex.www.ads-software.com/Function_Reference/get_post

    It is in wp-includes/post.php… however I do not suggest editing core files. You can use the get_post function to get a post by id and display its contents or write to a file or popup a new window that pulls that posts content and print that new window… possibilities are endless depending on how you want to do it and what your skillset is in making it happen.

    Thread Starter jansmith

    (@jansmith)

    alieneila,
    Thanks for your reply.
    I am using WordPress 3.4.2., and I have searched all PHP files for the Get_post function, including wp-includes/post.php. It isn’t in my version.

    Setting that to one side, perhaps if I gave more details, you could suggest a solution.

    I am using a theme called “Thesis”, which provides numerous “hooks” in which one may insert custom code. One of these hooks is labeled “these_hook_before_sidebar_1”. It contains the following code:]

    <?php
    if (is_single())  {
    ?>
    <div class="columntext" id="c4">
    	<ul class="columnlinks">
    
    <li><a>')">Printer-friendly page</a></li>
    </div>
    <?php } ?>

    [please mark all posted codes using the ‘code’ button – https://pastebin.com/ – the above section is already corrupted by the forum parser]

    (Elesewhere, there is logic that determines when this particular code runs. I use a plugin called “widget logic” for that.)

    This runs fine. A window appears, and it runs a file named “2printer.php, which is in a separate “include” directory (not in the WP directories.)

    Here is the contents of that PHP file. I have hard-coded an ID number, trying to get it to load the contents.

    But all I get is an error saying that the function “Get_post” cannot be found. I was hoping that if I “included” the PHP file containing that function, it would “find” the function and run it. Here’s my code:

    **********************************************************************
    <link rel="stylesheet" href="<?php echo $_SERVER['DOCUMENT_ROOT']?>/wordpress/wp-content/themes/thesis_18/custom/custom.css" type="text/css">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    
    <?php
    	$my_id = 1689;
    	$post_id_1689 = get_post($my_id);
    	$contents = $post_id_1689->post_content;
    	echo $contents;exit;
    
    </div>";
    ?>
    </body>
    </html>
    *********************************************************************

    As I say, when I run this, I get a window with an error message.

    All I want is a window with the contents of whatever post is being displayed in the “parent” window.

    I’m open to suggestions.

    Thanks ~ jan

    If your above code is an exact copy/paste… then there are problems in it…

    Furthermore, if your printer file is outside of wordpress, then just including the file with get_post in it will not work either because it relies on other files that for example, connects to the database, or provides the u/p for connecting to the database.

    I believe the proper way to “touch” wordpress so that you gain the functionality to perform outside tasks is by including wp-load.php into the file you want, such as your 2printer.php file you want to use.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘What file is function get_post() in?’ is closed to new replies.