Compare commits
	
		
			2 Commits
		
	
	
		
			00b7dbd0b7
			...
			42b8c3b8f1
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 42b8c3b8f1 | |||
| c6069b6f0d | 
							
								
								
									
										51
									
								
								wp-content/themes/simple-theme/api-posts/api-posts.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								wp-content/themes/simple-theme/api-posts/api-posts.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,51 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
add_action('rest_api_init', 'endlessPosts');
 | 
			
		||||
 | 
			
		||||
function endlessPosts()
 | 
			
		||||
{
 | 
			
		||||
 register_rest_route('api-posts/v1', "/endlessPosts", array(
 | 
			
		||||
    'methods' => WP_REST_Server::READABLE,
 | 
			
		||||
    'callback' => 'getEndlessPostsResults'
 | 
			
		||||
 ));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function getEndlessPostsResults($data, $paged = 1)
 | 
			
		||||
{
 | 
			
		||||
    global $wpdb;
 | 
			
		||||
 | 
			
		||||
    $link = $data['permalink'];
 | 
			
		||||
    $id_from_permalink = explode('/', $link);
 | 
			
		||||
    $id_from_permalink = explode('-', $id_from_permalink[3]);
 | 
			
		||||
 | 
			
		||||
    $id = $id_from_permalink[0];
 | 
			
		||||
 | 
			
		||||
    $category = get_the_category($id);
 | 
			
		||||
 | 
			
		||||
    $result = array();
 | 
			
		||||
 | 
			
		||||
    $args = array(
 | 
			
		||||
        'category__in' => $category[0]->term_id,
 | 
			
		||||
        'posts_per_page' => 10,
 | 
			
		||||
        'paged' => $paged
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    $posts = new WP_Query($args);
 | 
			
		||||
 | 
			
		||||
    while ( $posts->have_posts() ) {
 | 
			
		||||
        $posts->the_post();
 | 
			
		||||
 | 
			
		||||
        $terms = get_the_category();
 | 
			
		||||
 | 
			
		||||
        $result[] = array(
 | 
			
		||||
            'permalink' => get_the_permalink(),
 | 
			
		||||
            'terms'     => $terms[0]->slug,
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return $result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//"http://pamtest.ru/702-oformlenie-osago-na-a-b-c-d-otkryto-vsem-agenta/"
 | 
			
		||||
 | 
			
		||||
//"http://pamtest.ru/294-6-j-urok-kak-strahovomu-agentu-zadavat-voprosy-i-rabotat-s-vozrazheniyami/"
 | 
			
		||||
@@ -1,5 +1,8 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
require get_theme_file_path('/api-posts/api-posts.php');
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// ? get variables (globally)
 | 
			
		||||
function gV($gv)
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user