WordPress API single post

I’m grabbing a list of posts from Blog A to Blog B using the wordpress API, so far everything is fine, but how do I access the single post inside Blog B? How do I make it so when I access /blog/post-name it shows me the content from the same post from Blog A?

Anyone has an idea?

Go to Source
Author: Radu033

Pagination for custom categories template

I’m a newbie with wordpress theme creation. I want to create a custom category.php file, I’ve implemented the loop and it will display the last 8 posts. I have some fake posts to test if all works well, but I’m not able to add a pagination to the category template I have created.

How I can implement the pagination?I’m thinking to use an infinite scrll using the wp rest api but any other solution will be appreciated.
This is the code I’m using now, the previous link and the next are not displayed

<?php get_header(); ?>
<?php $current_cat = get_queried_object(); ?>
<div class="container mt-5 pt-5">
    <div class="row m-0">
        <div class="col-sm-12 col-md-12 col-lg-12 mt-2 mb-2">
            <p class="text-uppercase font-weight-bold mt-2 mb-2 section-title"><?php echo $current_cat->cat_name; ?></p>
        </div>  
<?php if( have_posts() ): while( have_posts() ): the_post(); ?>        
        <div class="col-sm-12 col-md-3 col-lg-3 h-100 mt-2 mb-2">
            <img class="img-fluid w-100 h-100" src="<?php echo the_post_thumbnail_url(); ?>">
            <a class="h5 mt-2 mb-2" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            <small class="text-muted d-block"><?php echo get_the_date('j F Y' ,$post->ID); ?></small>
        </div>
    <?php echo next_posts_link(); // not working?>
    <?php echo previous_posts_link(); // not working?>
<?php endwhile; endif; ?>    
    </div>
</div>

<?php get_footer(); ?>

Go to Source
Author: wpnewbie

How can I display Only the first Array/Object?

By using WordPress REST Api

./wp/v2/users/?_fields=id&orderby=id&order=desc

Result

[{“id”:13},{“id”:12},{“id”:11},{“id”:10},{“id”:9},{“id”:8},{“id”:6},{“id”:5},{“id”:4},{“id”:3}]

What I want?

I just want to display [{“id”:13},
Means, I want to limit it to only 1 array Using REST API. Any one have solution on this?

Go to Source
Author: Muhaza

Adding Custom Endpoint in WordPress Rest API

I have been working on custom WordPress rest API Endpoint. Goal is to create a WordPress custom route in this route i want to get Category Id and convert it to Category Name. I have written the function but its returning null for the category Id. The function simply get the categories of the WordPress and register the route.How Can I get the all Categories Id and convert category Id into category name.

{

    $categories = get_categories();

    $data = [];
    $i = 0;

    foreach ($categories as $category) {

        $data[$i]['id'] = $category->ID;
        $i++;
    }

    return $data;
}
add_action('rest_api_init', function () {
    register_rest_route('w/v2', 'trending', [
        'methods' => 'GET',
        'callback' => 'w_categories',
    ]);
});```

Go to Source
Author: Shahryar Rafique