# Simple php page to get post

**URL:** <https://discourse.getcockpit.com/t/simple-php-page-to-get-post/1305>\
**Category:** General\
**Created:** [March 31, 2020, 9:39am UTC](https://discourse.getcockpit.com/t/simple-php-page-to-get-post/1305 "2020-03-31T09:39:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/jonah/32/466_2.png) [@jonah](https://discourse.getcockpit.com/u/jonah)\
**Post date:** [March 31, 2020, 9:39am UTC](https://discourse.getcockpit.com/t/simple-php-page-to-get-post/1305/1 "2020-03-31T09:39:10Z")

</div>

I’m new at PHP (even though i’m coding in other languages(  
I have done a route in cockpit, so my single blogposts are routed to /blog/post and now I want to create a php page to list the post (so that google can follow slug links)

I’ve tried a simple page as follows, but it doesn’t show anything.  
Has anyone a simple example that works?

 ![php](https://canada1.discourse-cdn.com/flex030/uploads/getcockpit/original/1X/37ef11b7c77dd94035c16694ae581aeeb429ca6c.jpeg)

---

<div class="post-metadata">

**Author:** ![alessandro92](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@alessandro92](https://discourse.getcockpit.com/u/alessandro92)\
**Post date:** [March 31, 2020, 10:40am UTC](https://discourse.getcockpit.com/t/simple-php-page-to-get-post/1305/2 "2020-03-31T10:40:52Z")

</div>

Hi,

this code is an example, for me works.

```
  $project = cockpit('collections')->find('projects', [
    'filter' => [
      'published' => 'Published',
      'permalink' => $_GET['permalink']
    ]
  ]);

  if ( empty( $project ) ) {
    return [
      'message' => 'Not found'
    ];
  }

var_dump($project);

```

Your filter array seems incorrect.

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/jonah/32/466_2.png) [@jonah](https://discourse.getcockpit.com/u/jonah)\
**Post date:** [March 31, 2020, 11:23am UTC](https://discourse.getcockpit.com/t/simple-php-page-to-get-post/1305/3 "2020-03-31T11:23:00Z")

</div>

Thank you allesandro!  
It doesn’t work for me though. Am I including the right bootstrap.php?  
It is the one in the root.

Do I need to provide token? If so, where do I put it?

Cheers!

- jonah

---

<div class="post-metadata">

**Author:** ![artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/artur/32/4_2.png) [@artur](https://discourse.getcockpit.com/u/artur)\
**Post date:** [March 31, 2020, 1:52pm UTC](https://discourse.getcockpit.com/t/simple-php-page-to-get-post/1305/4 "2020-03-31T13:52:06Z")

</div>

strange, it should work. do yo get any errors?

also try `$posts->toArray()`

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/jonah/32/466_2.png) [@jonah](https://discourse.getcockpit.com/u/jonah)\
**Post date:** [April 1, 2020, 5:38am UTC](https://discourse.getcockpit.com/t/simple-php-page-to-get-post/1305/5 "2020-04-01T05:38:58Z")

</div>

Hi Artur!  
I needed to require the bootstrap file, instead of including it.  
This is what I got now, and this works!  
My url is as follows: [www.mydomain.com/blog/my-slug](http://www.mydomain.com/blog/my-slug)

This is my code, for reference.

```
                require_once("../admin/bootstrap.php");

                $post = cockpit('collections')->find('posts', [
                    'filter' => ['slug' => basename($_SERVER['REQUEST_URI'])]
                ])[0];

                $date = $post["date"];
                $title = $post['title'];
                
                $content = $post['content'];
                $featured_image = $post['feature_image'];
```

---

<div class="post-metadata">

**Author:** ![artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/artur/32/4_2.png) [@artur](https://discourse.getcockpit.com/u/artur)\
**Post date:** [April 1, 2020, 2:53pm UTC](https://discourse.getcockpit.com/t/simple-php-page-to-get-post/1305/6 "2020-04-01T14:53:25Z")

</div>

there shouldn’t be any difference between require and include 🤔

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [April 2, 2020, 4:24pm UTC](https://discourse.getcockpit.com/t/simple-php-page-to-get-post/1305/7 "2020-04-02T16:24:20Z")

</div>

> [@jonah](#):
>
> I needed to require the bootstrap file, instead of including it.

No, you needed the brackets 😉  
`<?php include('../admin/bootstrap.php'); ?>`

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/jonah/32/466_2.png) [@jonah](https://discourse.getcockpit.com/u/jonah)\
**Post date:** [April 3, 2020, 5:32am UTC](https://discourse.getcockpit.com/t/simple-php-page-to-get-post/1305/8 "2020-04-03T05:32:57Z")

</div>

Haha! 😬  
Thanks!
