[Resolved] hook element display rules have a mind of their own

Home Forums Support [Resolved] hook element display rules have a mind of their own

Home Forums Support hook element display rules have a mind of their own

Viewing 12 posts - 16 through 27 (of 27 total)
  • Author
    Posts
  • #1404556
    Leslie

    Hi again David. It seems to be working like this:

    add_action( ‘generate_search_placeholder’, function() {
    return __( ‘search investment funds…’, ‘Search …’ );
    } );
    echo do_shortcode( ‘[searchform post_types=”inv_funds,glossary”]’ );

    This code is in a generate_before_content_hook, displayed on certain CPT and custom taxonomy archive pages.

    The display selection still jumps around in the back end menu, but I don’t think it’s impacting front end performance.

    I know you said “add filter” shouldn’t go into hooks. Is “add action” ok for a hook?

    A separate puzzle I’d like to solve relates to highlighting of my secondary nav menu items. The user sees one of my custom searchforms after they click on a topic from my secondary nav menu. Once they do a searh and arrive at the search results page, the secondary nav menu item is no longer highlighted. I’m going to research ways of keeping the menu item highlighted so that the user is reminded what part of the website they began searching from, but if you have a quick answer (or if I should open a new support topic) please let me know. Thanks as always for your support. Leslie

    #1404946
    David
    Staff
    Customer Support

    Well i am surprised that works!
    My thoughts were something like this:

    add_filter( 'generate_search_placeholder', 'db_custom_search_placeholder' );
    function db_custom_search_placeholder( $text ) {
        if ( is_category() ) {
            $text = 'Search ' . single_cat_title("", false);
        } elseif ( is_page() ) {
    	$text = 'Search ' . get_the_title();
        }
        return $text;
    }

    Which should add the current title into the search placeholder.

    Can you raise a separate topic regarding the navigation.

    #1405303
    Leslie

    Thanks David. I am going to keep the “add action” method in the hooks because it seems to be working without errors and it allows me to use pick one of my three custom searchforms for use on various CPT and archive pages.

    I’ll open another support topic if I run into problems later.

    I’ll open a new topic now on the other question.

    #1405469
    David
    Staff
    Customer Support

    Glad to hear that ๐Ÿ™‚

    #1433221
    Leslie

    Hi GP team, I have to ask you again about putting different search forms on different CPT taxonomy archive pages.

    Background: I have two search forms (shortcode from Relevanssi) that I am using to restrict search results by CPT (i.e. by topic). The CPTs are “ewir,” “inv_funds” and “glossary.” These post types share the custom taxonomy “sources.”

    Current code: My first GP hook element is like this:

    <?php
    add_action( ‘generate_search_placeholder’, function() {
    return __( ‘search investment funds…’, ‘Search …’ );
    } );
    echo do_shortcode( ‘[searchform post_types=”inv_funds,glossary”]’);
    ?>

    This restricts search results to two CPTs: “inv_funds” and “glossary.” The display rules are set to

    –all inv_funds pages [this works fine], and

    –inv_funds sources taxonomy archives.

    Problem: This search form sometimes appears on the correct “sources” taxonomy archives and sometimes does not. When I double check my display rules, I see they have changed randomly on their own.

    I have another GP hook element similar to the above, but it resticts searches to the CPT “ewir.” The display rules include ewir sources taxonomy archives, not inv_funds sources taxonomy archives.

    Tom suggested in an earlier post that the problem might arise because all three of my CPTs share the taxonomy “sources.”

    I think I need to move the code out of hook elements and write something more explicit about display rules in my child theme functions.php. Can you help me do that or point me in the right direction?

    Here is an example of a sources taxonomy archive page, showing both search forms, so I think the display rules aren’t distinguishing “sources” of ewirs from “sources” of inv_funds: http://lexata.kinsta.cloud/sources/national-instrument-81-102-investment-funds/.

    The proper search forms show on non-taxonomy archive pages, for example the inv_funds search form here: http://lexata.kinsta.cloud/investment-funds/#rules and the ewir search form here: http://lexata.kinsta.cloud/early-warning-and-insider-reporting-home-page/.

    Thanks very much GP team.

    #1434254
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    I’m only seeing one search form here: http://lexata.kinsta.cloud/sources/national-instrument-81-102-investment-funds/

    I wonder if there’s another Display Rule you can use that doesn’t have the potential to conflict?

    #1434307
    Leslie

    Sorry I was experimenting after I sent you the link. Here is what I mean: http://lexata.kinsta.cloud/sources/national-instrument-81-102-investment-funds/

    I am going to try displaying the search forms on “all archives” and then excluding the taxonomy archives that aren’t relevant. I’ll let you know what that does.

    #1434473
    Tom
    Lead Developer
    Lead Developer

    It’s strange that the values are combining/getting mixed up like that. How are you building these custom taxonomies?

    #1435006
    Leslie

    It’s just one custom taxonomy, “sources,” which has multiple terms, and those terms each have child terms. There are two CPTs. Each post belongs to exactly one child term. The two post types only share the ultimate parent “sources.” It’s like this:

    sources/term-abc/child-term-1/CPT-x

    sources/term-xyz/child-term-2/CPT-y

    I set the display rules to “CPT-x sources archives, all sources” for one of the search forms and “CPT-y sources archives, all sources” for the other search form. If I had a small number of taxonomy terms and child terms, I could try setting them individually instead of “all sources” but that’s too labor intensive.

    #1435859
    Tom
    Lead Developer
    Lead Developer

    Would you be willing to send me temporary admin login details so I can take a look at the code for the select dropdowns? I want to see if they’re sharing a value for some reason. If so, you can send the details through the Account Issue form here: https://generatepress.com/contact – just be sure to link to this topic.

    Thank you! ๐Ÿ™‚

    #1436959
    Leslie

    Done, thanks.

    #1436966
    Leslie

    Note: the ewir hook element shows what I’ve been attempting to do. The inv_funds element specifies some of the archive pages individually, to test if that method works instead of just “all sources.” That’s why there are so many display locations (but there are too many more for this method to be practical).

Viewing 12 posts - 16 through 27 (of 27 total)
  • You must be logged in to reply to this topic.