WordPress.org

Forums

Contextual Related Posts
[resolved] Bad default behavior in crp_shortcode() (8 posts)

  1. flynsarmy
    Member
    Posted 1 year ago #

    In crp_shortcode() you're calling

    extract( shortcode_atts( array(
    	'limit' => '5',
    	'heading' => '1',
    	'cache' => '1',
    ), $atts ) );

    which is actively ignoring and overriding the settings provided in the admin area resulting in confusing behavior. You shouldn't be providing overrides by default - it should act the way it's set to act in the admin unless specified otherwise.

    http://wordpress.org/plugins/contextual-related-posts/

  2. Ajay
    Member
    Plugin Author

    Posted 1 year ago #

    Would something like this sense to do something like this:

    global $crp_settings;
    extract( shortcode_atts( array(
    	'limit' => $crp_settings['limit'],
    	'heading' => $crp_settings['heading'],
    	'cache' => $crp_settings['cache'],
    ), $atts ) );
  3. flynsarmy
    Member
    Posted 1 year ago #

    I think

    function crp_shortcode( $atts, $content = null ) {
    	$atts = shortcode_atts( array(
    		'is_widget' => 1,
    	), $atts );
    
    	return ald_crp($atts);
    }

    is enough. Allows every setting to be overridable while letting ald_crp take care of handling defaults and overrides. I haven't tested this but don't see why you'd need to specify the rest.

  4. Ajay
    Member
    Plugin Author

    Posted 1 year ago #

    I'll give it a try, but from what I see above a user could just put any attribute based on the settings and the plugin should ideally handle this (subject to testing, of course)

  5. flynsarmy
    Member
    Posted 1 year ago #

    Hmm, then perhaps

    function crp_shortcode( $atts, $content = null ) {
    	global $crp_settings;
    	$atts = shortcode_atts(array_merge(
    		$crp_settings,
    		array('is_widget' => 1),
    	), $atts );
    
    	return ald_crp($atts);
    }
  6. Ajay
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks, will give me a test run.

  7. noyz319
    Member
    Posted 1 year ago #

    Just checking in to see if there's been any update on this? I would love it if I could simply type the [crp] shortcode and have it follow the plugin settings regarding limit etc.

    I only want 2 posts to show up every time, but have to add [crp limit="2"] instead of simply [crp] otherwise it ignores the plugin settings and defaults to 5 every time.

  8. Ajay
    Member
    Plugin Author

    Posted 1 year ago #

    Hi, this will be in the next release of the plugin.

    For now, you can give flynsarmy's code above by editing the plugin.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Contextual Related Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.