Archived

This topic is now archived and is closed to further replies.

  • 0

Resolved PLOption not being applied when chosen from within page


Question

Posted · Report post

I have created a custom section, which uses wp_query to pull out posts of a particular category only. The section is intended to be used on custom page templates. I have created an option for this, so that the user can choose the category of posts that should be displayed. The option is a simple dropdown containing the list of categories.

When I select a category from site wide options, it all works fine - only the posts in the chosen category are displayed. But when I select a category from the page options, it isn't applied. Here is my code:

Setting up the option in my section .php file:


function section_optionator( $settings ){

	 $settings = wp_parse_args( $settings, $this->optionator_default );

	 $array = array();

	 $categories = get_categories( $args );

	 $cat_arr = array();

	 foreach ($categories as $category) {

		 $cat_arr[$category->category_nicename] = array('name' => $category->cat_name);

	 }

	 $array['aamhc_post_loop_categories'] = array(

		 'type'			 => 'select',

		 'selectvalues' => $cat_arr,

		 'inputlabel'	 => __( 'Select Category:', 'pagelines' ),

		 'title'		 => __( 'Choose a category. Posts from this category will be displayed', 'pagelines' ),

		 'shortexp'		 => __( 'Choose a cetgory of posts to display', 'pagelines' ),

		 'exp'			 => __( "", 'pagelines' ),

	 );

	 $metatab_settings = array(

		 'id'		 => 'AAMHCPostLoopCat',

		 'name'		 => __( 'AAHMC Posts Loop (Category)', 'pagelines' ),

		 'icon'		 => $this->icon,

		 'clone_id' => $settings['clone_id'],

		 'active' => $settings['active']

	 );

	 register_metatab( $metatab_settings, $array );

}

Pulling out the option:

$cat_posts = new WP_Query();

$cat_posts->query('showposts=5&category_name=' . ploption('aamhc_post_loop_categories', $this->oset));

I had a look at the developer docs but the options section doesn't seem to be populated. Any help on how I can apply the option when selected from the page would be much appreciated.

Many Thanks,

John

Share this post


Link to post
Share on other sites

8 answers to this question

Posted · Report post

Is this resolved? I couldn't tell from your last comments.

Share this post


Link to post
Share on other sites

Posted · Report post

Yes, it's working now. Thanks.

Share this post


Link to post
Share on other sites

Posted · Report post

Well, we need the links to what you posted. There are tens of thousands of postings in the pastebin.

Sorry, I should have explained that.

Share this post


Link to post
Share on other sites

Posted · Report post

Can you paste the full code here?

http://paste.pagelines.com/

Share this post


Link to post
Share on other sites

Posted · Report post

Hi Rob,

Thanks for getting back to me. I've pasted the following:

section.php

AAMHCPostsCategory (a supporting class, which extends pagelinesposts)

functions.php

Let me know if you need anything else.

Share this post


Link to post
Share on other sites

Posted · Report post

The topic was marked as resolved.

Share this post


Link to post
Share on other sites

Posted · Report post

I have sussed this one out. I replaced $this->oset with an array and populated the items individually. Here is the old code:


function load_loop(){

	 $cat_posts = new WP_Query();

	 $cat_posts->query('showposts=5&category_name=' . ploption('aamhc_post_loop_categories', $this->oset));

I replaced it with the following:

function load_loop($this_id){


	 // Get the current page id

	 global $wp_query;

	 $thePostID = $wp_query->post->ID;


	 // Create the wp query object

	 $cat_posts = new WP_Query();


	 // Execute the query pulling in the option. Instead of using $this->oset, specify each element of the array individually, so that we can add the page id manually.

	 $cat_posts->query('showposts=5&category_name=' . ploption('aamhc_post_loop_categories', array(

		 'post_id' => $thePostID,

		 'clone_id' => NULL,

		 'group' => $this_id

	 )));

Share this post


Link to post
Share on other sites