WordPress.org

Ready to get started?Download WordPress

Forums

Metaphor Shortcodes
[resolved] Post block for specific category (12 posts)

  1. msbodetti
    Member
    Posted 1 year ago #

    I'm using the content blocks with the zen theme I purchased. I am currently letting the posts load with offset in the post_block shortcode.

    Is there no parameter to set in the shortcode for specific category or categories?

    http://wordpress.org/extend/plugins/mtphr-shortcodes/

  2. metaphorcreations
    Member
    Plugin Author

    Posted 1 year ago #

    There is not a parameter for categories yet, but I will add that into the next update. If you are familiar with using WordPress filters, you can add/modify the post query any way that you'd like using:

    function custom_post_block_query_args( $args ) {
    	$args['category_name'] = 'my-category';
    	return $args
    }
    add_filter( 'mtphr_post_block_query_args', 'custom_post_block_query_args' );
  3. msbodetti
    Member
    Posted 1 year ago #

    Thanks for the reply!

    Will this update all the post blocks?

  4. metaphorcreations
    Member
    Plugin Author

    Posted 1 year ago #

    Yes, but you could figure out an if/then statement based on the other $args being passed through to limit the additional argument to only certain post blocks. I don't have time to go more in depth on that right now, but if you need more help let me know.

  5. msbodetti
    Member
    Posted 1 year ago #

    It's not working, I don't know if it needs a specific or other $tag.
    Please assist. Or if you have any updates on your plugin, let me know. Thanks :)

    <?php
    /*
    Plugin Name:
    Plugin URI:
    Description:
    Author:
    Author URI:
    Version: 1.0
    */
    
    function custom_post_block_query_args($args){
    	$args['category_name'] = 'News';
    	return $args;
    }
    
    add_filter('mtphr_post_block_query_args', 'custom_post_block_query_args');
    ?>
  6. metaphorcreations
    Member
    Plugin Author

    Posted 1 year ago #

    Try using:

    $args['category_name'] = 'news';

    otherwise try a different category query method, like:

    $args['cat'] = '22';

    Where "22" is the category ID of the category you are trying to filter.

  7. msbodetti
    Member
    Posted 1 year ago #

    Still not working..

    Have you tried this already?

  8. msbodetti
    Member
    Posted 1 year ago #

    I just added it to your plugin general.php file and it works:

    Line 193 Function:

    function mtphr_post_block( $atts, $content = null ) {
    	extract( shortcode_atts( array(
    		'id' => '',
    		'class' => '',
    		'type' => 'post',
    		'orderby' => 'date',
    		'order' => 'DESC',
    		'offset' => '0',
    		'trim' => 120,
    		'category_name' => 'news'
    	), $atts ) );

    Would like it to work as a parameter though..

  9. metaphorcreations
    Member
    Plugin Author

    Posted 1 year ago #

    I just tested my first example and it was working fine. I was missing a ";" after "return $args", which may have caused an issue. It should be:

    function custom_post_block_query_args( $args ) {
    	$args['category_name'] = 'news';
    	return $args;
    }
    add_filter( 'mtphr_post_block_query_args', 'custom_post_block_query_args' );

    But, I will be adding this argument in the next update in the next few weeks.

  10. msbodetti
    Member
    Posted 1 year ago #

    I did add the semi-colon after the return, it still wasn't working. Look above.

    Unless you weren't using it in your Zen Theme, and it worked.

  11. msbodetti
    Member
    Posted 1 year ago #

    Well it worked for me by editing your general.php file. Looking forward to getting your update for the plugin!

  12. metaphorcreations
    Member
    Plugin Author

    Posted 1 year ago #

    Ok. Well, I'll try to get that update out soon.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic