custom post types – Finding the CPT archive template source

I’ve created a CPT named kindergarten by a plugin ;
I was able to see the archive page of this custom post type with its posts;
When I was using Elementor for changing the template of this post type, I don’t know what happened that I see a message that there is no posts for that; like this:
enter image description here

I’ve created a archive-kindergarten.php for test, But I don’t see any change.
How can I find what is the source for this CPT template?
How can I force WordPress to use elementor template as an archive template for this post type?
(I have to mention that posts work perfectly but archive page doesn’t )

java – How to optimize the check for data types before building an object?

I’m trying to build an object, which uses different methods based on different data types. I.e. it differs from withBooleanValue,withStringValue and withDateValue depending on the data type. What I have is a string, and depending on what that string is (boolean, string or date), I need to build this object. Below is how I went about it.

private List<Answer> getAnswers(Set<Question> questions) {
        List<Answer> answers = new ArrayList<>();
        questions.forEach(question -> {
            Answer.Builder answer = Answer.builder()
                    .withQuestion(question.question());
            if (BooleanUtils.toBooleanObject(question.value()) != null) {
                answer.withValue(AnswerValue.builder()
                        .withBooleanValue(BooleanUtils.toBoolean(question.value()))
                        .build());
            } else {
                try {
                    Date dateValue = DateUtils.parseDate(question.value(), new String(){"dd-MM-YYYY"});
                    answer.withValue(AnswerValue.builder()
                            .withDateValue(dateValue)
                            .build());

                } catch (ParseException e) {
                    answer.withValue(AnswerValue.builder()
                            .withStringValue(question.value())
                            .build());
                }
            }
            answers.add(answer.build());
        });
        return answers;
    }

Is there a better way to do this? Somehow the ifs, and try-catch statements make it look very complicated and I’d like to reduce the lines and complexity with a better way.

plugin development – URL issue retrieving Custom Post Types using Backbone JS API

I have a Custom Post Type called pronews. I registered it with show_in_rest enabled. I’m using WordPress 5.5.

I then have this code:

export const ProPost  = wp.api.models.Post.extend( {
    urlRoot: wpApiSettings.root + 'wp/v2/pronews',
    defaults: {
        type: 'pronews',
    },
} );
export const ProPosts = wp.api.collections.Posts.extend( {
    url: wpApiSettings.root + 'wp/v2/pronews',
    model: ProPost,
} );

const post = new ProPost( {id: 2454} );

console.log( post );
console.log( 'post urlRoot:' + post.urlRoot );
console.log( 'post url:' + post.url );

post.fetch().then( ( response ) => {
    console.log( response )
}, ( why ) => {
    console.log( why.responseJSON.code )
} );

// Double check that the endpoint is functionnal
fetch( wpApiSettings.root + 'wp/v2/pronews/2454' )
    .then( blob => blob.json() )
    .then( ( response ) => {
        console.log( response.id );
    } );

In the console I first get:

{…}
​_changing: false
​_pending: false
​_previousAttributes: Object { type: "pronews", id: 2454 }
​attributes: Object { type: "pronews", id: 2454 }
​changed: Object {  }
​cid: "c3"
​id: 2454
​<prototype>: Object { urlRoot: "https://localhost/wp-json/wp/v2/pronews", defaults: {…}, constructor: i()
 }
ProNews.js:17:9
post urlRoot:https://localhost/wp-json/wp/v2/pronews ProNews.js:18:9
post url:function(){var e=a.get("apiRoot")+a.get("versionString")+("me"===i?"users/me":i);return _.isUndefined(this.get("id"))||(e+="/"+this.get("id")),e} ProNews.js:19:9

But the Backbone API’s request is done to the wrong urlRoot :

XHRGET https://localhost/wp-json/wp/v2/posts/2454 (HTTP/1.1 404 Not Found 340ms)
rest_post_invalid_id

For debugging, the result of the second HTTP Request using window.fetch, shows that the endpoint for the Custom Post Type exists and is functional:

XHRGET https://localhost/wp-json/wp/v2/pronews/2454 (HTTP/1.1 200 OK 587ms)
2454

signature – signing multiple input raw transaction – algorithm and sighash types

I have an unsigned raw transaction:

01000000020dcc23ccdb3665779a7657577cd33c5c0660e969ea2ffaf5438c58306ebc9dd20100000000ffffffff49508924c21b25ee2ff6aed61ccc202793aa992d3e033f12f2bf4a94d6346d010000000000ffffffff0240420f00000000001976a9140d7ca1e17524d6c96209cf503fb053613cecf8f688aca0f703000000000017a91452636ce984783dac880e139fa3b69b4d9be39ab68700000000

I have read these threads:
How to redeem a basic Tx?
Redeeming a raw transaction step by step example required

These threads explain signing a raw transaction with 1 input.

Questions

Do I understand correctly that both inputs are to signed separately?
So first, we sign the first one, then the second one. To sign an input we replace scriptSig for this input with the scriptPubKey, that locks this input. ScriptSig for the other one remains blank.

It this correct?

But in both threads in step 13 something is appended at the end of transaction. It is called hash code type

What is this? Is this has anything to do with sighash type byte the one that is appended to the signature? If not how to determine this value?

What is the correct sighash type for the scenario I described above (signing inputs separately)?
Is this: 0x81 (SIGHASH_ALL | SIGHASH_ANYONECANPAY)?
Or should this be 0x01 (SIGHASH_ALL)?

I don’t know which one is correct as transaction to be signed contains the other input (without scriptSig set but still, it contains it).

javascript – Build a stamp duty calculator for various types of buyers

I had a task where I had to build a stamp duty calculator, which calculates the tax or stamp duty first-time buyers(ftb) returning buyers (rtb), and second-home buyers (shb) had to pay when purchasing the home.

These were the tax bands, although I think some of the percentages may be slightly wrong.

First Time Buyers
0 to £300,000 - 0%
£300,001 to £925,000 - 5%
£925001 to £1,500,000 - 10%
£1,500,000 and above - 12%

Returning Buyers
0 to £125,000 - 0%
£125,001 to £250,000 - 2%
£250,001 to £925,000 - 5%
£925,001 to £1,500,000 - 10%
£1,500,000 and above - 12%

Second Home Buyers
0 to £125,000 - 3%
£125,001 to £250,000 - 5%
£250,001 to £925,000 - 8%
£925,001 to £1,500,000 - 13%
£1,500,000 and above - 15%

Here is my solution, I look forward to the feedback.

const stampDutyCalc = (price) => {
  let stampdutyObject = {
    ftb: 0,
    rtb: 0,
    shb: 0,
  };

  firstTimeBuyerCalc(price, stampdutyObject);
  returningBuyerCalc(price, stampdutyObject);
  secondHomeBuyerCalc(price, stampdutyObject);

  return stampdutyObject;
};

function firstTimeBuyerCalc(price, stampdutyObject) {
  if (price <= 300000) {
    stampdutyObject.ftb += 0;
  } else if (price > 300000 && price <= 925000) {
    stampdutyObject.ftb += price * 0.05;
  } else if (price > 925000 && price <= 1500000) {
    stampdutyObject.ftb += (price - 925000) * 0.1 + (925000 - 300000) * 0.05;
  } else {
    stampdutyObject.ftb +=
      (price - 1500000) * 0.12 +
      (1500000 - 925000) * 0.1 +
      (925000 - 300000) * 0.05;
  }
}

function returningBuyerCalc(price, stampdutyObject) {
  if (price <= 125000) {
    stampdutyObject.rtb += 0;
  } else if (price > 125000 && price <= 250000) {
    stampdutyObject.rtb += price * 0.02;
  } else if (price > 250000 && price <= 925000) {
    stampdutyObject.rtb += (price - 250000) * 0.05 + (250000 - 125000) * 0.02;
  } else if (price > 925000 && price <= 1500000) {
    stampdutyObject.rtb +=
      (price - 925000) * 0.1 +
      (925000 - 250000) * 0.05 +
      (250000 - 125000) * 0.02;
  } else {
    stampdutyObject.rtb +=
      (price - 1500000) * 0.12 +
      (1500000 - 925000) * 0.1 +
      (925000 - 250000) * 0.05 +
      (250000 - 125000) * 0.02;
  }
}

function secondHomeBuyerCalc(price, stampdutyObject) {
  if (price <= 125000) {
    stampdutyObject.shb = price * 0.03;
  } else if (price > 125000 && price <= 250000) {
    stampdutyObject.shb += (price - 125000) * 0.05 + 125000 * 0.03;
  } else if (price > 250000 && price <= 925000) {
    stampdutyObject.shb +=
      (price - 250000) * 0.08 + (250000 - 125000) * 0.05 + 125000 * 0.03;
  } else if (price > 925000 && price <= 1500000) {
    stampdutyObject.shb +=
      (price - 925000) * 0.13 +
      (925000 - 250000) * 0.08 +
      (250000 - 125000) * 0.05 +
      125000 * 0.03;
  } else {
    stampdutyObject.shb +=
      (price - 1500000) * 0.15 +
      (1500000 - 925000) * 0.13 +
      (925000 - 250000) * 0.08 +
      (250000 - 125000) * 0.0 +
      125000 * 0.03;
  }
}

function returningBuyerCalc(price, stampdutyObject) {
  if (price <= 125000) {
    stampdutyObject.rtb += 0;
  } else if (price > 125000 && price <= 250000) {
    stampdutyObject.rtb += price * 0.02;
  } else if (price > 250000 && price <= 925000) {
    stampdutyObject.rtb += (price - 250000) * 0.05 + (250000 - 125000) * 0.02;
  } else if (price > 925000 && price <= 1500000) {
    stampdutyObject.rtb +=
      (price - 925000) * 0.1 +
      (925000 - 250000) * 0.05 +
      (250000 - 125000) * 0.02;
  } else {
    stampdutyObject.rtb +=
      (price - 1500000) * 0.12 +
      (1500000 - 925000) * 0.1 +
      (925000 - 250000) * 0.05 +
      (250000 - 125000) * 0.02;
  }
}

Magento 1 Export attributes of different types (via script form)

I was trying to create some robust form of exporting EAV values from the DB. Idea is to have a basic set of columns … then the admin can enter the attribute they want to add to the collection. The code below is working for most attribute types … long text, dropdown … but not! simple text values.

(assume _POST("attributecodes") contains comma separated list of existing attribute types)

$attributes = array();
if (isset($_POST("attributecodes")) && !empty($_POST("attributecodes"))) {
    $attribute_codes = array_map('trim', explode(',', $_POST("attributecodes")));
    foreach ($attribute_codes as $attribute_code) {
        $attribute_code = trim($attribute_code, ',');
        $attribute = Mage::getSingleton('catalog/product')->getResource()->getAttribute($attribute_code);
        if (!$attribute) {
            print("Attribute with code {$attribute_code} does not exist");
            Mage::throwException("Attribute with code {$attribute_code} does not exist");
            exit;
        } else {
            if ( ($attribute->getFrontendInput() === 'select' && $attribute->getSource() instanceof Mage_Eav_Model_Entity_Attribute_Source_Table) ||
                 ($attribute->getFrontendInput() === 'multiselect' && $attribute->getBackend() instanceof Mage_Eav_Model_Entity_Attribute_Backend_Array) ) {
                    $data->addAttributeToSelect($attribute_code . '_value');
            } else {
                $data->addAttributeToSelect($attribute_code);
            }
        }
    }
}

custom post types – Different URL depending on taxonomy?

Is it possible to create a custom post type with 2 custom taxonomies that will have different URL depending on the taxonomy?

Let's say I have created "custom_post" and assigned it to both taxonomies:

This is the structure I would love to have:

taxonomy_one/custom_post
taxonomy_two/custom_post

And then connect these to the custom template page-taxonomy_one.php & page-taxonomy_two.php depending on that URL to display a different layout.

So main question will be IS this possible? If yes, how :]

Find a recurrence relation for $a_{n,k}$ , the number of ways to order n doughnuts from k different types of doughnuts if

Find a recurrence relation for $a_{n,k}$ , the number of ways to order n doughnuts from k different types of doughnuts if two or four or six doughnuts must be chosen of each type.

I need help understanding the answer to this.

So I know the answer to this is

$a_{n,k}=a_{n-2,k-1} + a_{n-4,k-1}+a_{n-6,k-1}$

so I know that $a_{n-2,k-1}$ means you start by picking $2$ donuts of one type, then you pick the remaining $n-2$ donuts from the other $k-1$ types

$a_{n-4,k-1}$ means you start by picking $4$ donuts of one type, then you pick the remaining $n-4$ donuts from the other $k-1$ types

$a_{n-6,k-1}$ means you start by picking $6$ donuts of one type, then you pick the remaining $n-6$ donuts from the other $k-1$ types

But how does this satisfy the constraint that two or four or six doughnuts must be chosen of each type? That’s what I’m confused by. Can’t you just pick any amount of each type of donut from the other $k-1$ types, not just two or four or six.

If someone can explain this to me, I would really appreciate it.