Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Wordpress posts be rendered dynamically?

I want to make a blog page which is generating content for particular user based on his/her Facebook likes, activity etc. For example I like Shakira and Coca Cola on Facebook. When entering the blog and connecting via Facebook, the blog gets that info and searches for Shakira's YouTube video through YouTube API and shows me the video in a WordPress post. After the blog searches for news connected with Coca Cola and shows news about it also in a post.

There is no problem with FB connect, YouTube search or Google search. My problem is WordPress. As there can be a lot of users and a lot of content can be generated for each user, I can't save every post in MySQL table. I want to generate posts dynamically. I'm not asking for code here, I just want to hear good solutions and ideas how can this be done.

like image 545
Yervand Khalapyan Avatar asked Dec 19 '13 14:12

Yervand Khalapyan


People also ask

How do I create a dynamic post in WordPress?

To create your own custom dynamic page using WPBakery is as easy as using the elements provided by the builder. Start by creating a new page by going to Pages > Add New in the left WordPress menu. Add a title to the new page like “blog” or something similar. Next click the Add Element button to open the elements popup.

Does WordPress allow dynamic content?

Dynamic Content for Elementor enhances the dynamic possibilities of the visual builder. It features a set of widgets and extensions that helps to display dynamic content. It is compatible with WooCommerce, WPML, Toolset, Pods, and many other WordPress solutions.

How do I create a dynamic content page in WordPress?

To do this navigate to the WordPress Customizer, then head to Portfolio and select the template you just created under Dynamic template (Advanced). You can now see your media in action. Click Save & Publish and your dynamic content should be ready.

What is a dynamic post?

The Dynamic Posts widget allows you to build archives from lists of articles based on 4 different type of queries: Custom Post Type and Taxonomy; Dynamic, depending on where you place it; ACF Relations; From Specific Posts.


1 Answers

As a solution you could use the 404 page to generate this dynamic post.

There's a blog post here that gives a similar solution: http://www.blogseye.com/creating-fake-wordpress-posts-on-the-fly/

The code used to generate the fake posts:

function kpg_f_content() {
    global $wp_query;
    if($wp_query->is_404 ) {
        $id=-42; // need an id
        $post = new stdClass();
            $post->ID= $id;
            $post->post_category= array('uncategorized'); //Add some categories. an array()???
            $post->post_content='hey here we are a real post'; //The full text of the post.
            $post->post_excerpt= 'hey here we are a real post'; //For all your post excerpt needs.
            $post->post_status='publish'; //Set the status of the new post.
            $post->post_title= 'Fake Title'; //The title of your post.
            $post->post_type='post'; //Sometimes you might want to post a page.
        $wp_query->queried_object=$post;
        $wp_query->post=$post;
        $wp_query->found_posts = 1;
        $wp_query->post_count = 1;
        $wp_query->max_num_pages = 1;
        $wp_query->is_single = 1;
        $wp_query->is_404 = false;
        $wp_query->is_posts_page = 1;
        $wp_query->posts = array($post);
        $wp_query->page=false;
        $wp_query->is_post=true;
        $wp_query->page=false;
    }
}

add_action('wp', 'kpg_f_content');

Make this into a plugin or add it to the functions.php file.

like image 62
ajtrichards Avatar answered Sep 23 '22 01:09

ajtrichards