WordPress.org

Ready to get started?Download WordPress

Forums

Page Categories (2 posts)

  1. Ambran.Com
    Member
    Posted 2 years ago #

    Hi
    I've just added the posobility to attach a category to a page:

    if(!function_exists('abg_ThemeInit')) {
       function abg_ThemeInit() {
    	register_taxonomy_for_object_type('post_tag', 'page');
    	register_taxonomy_for_object_type('category', 'page');
       }
       add_action( 'admin_init', 'abg_ThemeInit' );
    }
    if(!function_exists('abg_PageTagger')) {
    	function abg_PageTagger($query) {
    		if ($query->is_archive && ($query->is_category || $query->is_tag)) {
    			$q = $query->query_vars;
    			$q['post_type'] = 'any';
    		}
    	}
    	add_action('pre_get_posts', 'abg_PageTagger');
    }

    It works fine as I can attach a certain category to any page just like blog posts.

    Now I would like to find all pages related to a specific category, fx. get all page ids of category "RequiresLogin".

    In this function I redirect specific page ids to the login page:

    function my_force_login() {
    	global $post;
    	if (!is_page()) return;
    	$ids = array(2,5,7); // array of post IDs that force login to read
    
    	if (in_array((int)$post->ID, $ids) && !is_user_logged_in()) {
    		auth_redirect();
    	}
    }

    How do I locate the page ids of a certain category.

    Thanks for any help
    Amit

  2. Ambran.Com
    Member
    Posted 2 years ago #

    Any one has a clue?

Topic Closed

This topic has been closed to new replies.

About this Topic